pinecone.config.config

  1from typing import NamedTuple, Optional, Dict
  2import os
  3
  4from pinecone.exceptions.exceptions import PineconeConfigurationError
  5from pinecone.config.openapi import OpenApiConfigFactory
  6from pinecone.openapi_support.configuration import Configuration as OpenApiConfiguration
  7
  8
  9# Duplicated this util to help resolve circular imports
 10def normalize_host(host: Optional[str]) -> str:
 11    if host is None:
 12        return ""
 13    if host.startswith("https://"):
 14        return host
 15    if host.startswith("http://"):
 16        return host
 17    return "https://" + host
 18
 19
 20class Config(NamedTuple):
 21    api_key: str = ""
 22    host: str = ""
 23    proxy_url: Optional[str] = None
 24    proxy_headers: Optional[Dict[str, str]] = None
 25    ssl_ca_certs: Optional[str] = None
 26    ssl_verify: Optional[bool] = None
 27    additional_headers: Optional[Dict[str, str]] = {}
 28    source_tag: Optional[str] = None
 29
 30
 31class ConfigBuilder:
 32    """
 33
 34    Configurations are resolved in the following order:
 35
 36    - configs passed as keyword parameters
 37    - configs specified in environment variables
 38    - default values (if applicable)
 39    """
 40
 41    """Initializes the Pinecone client.
 42
 43    :param api_key: Required if not set in config file or by environment variable ``PINECONE_API_KEY``.
 44    :param host: Optional. Controller host.
 45    :param openapi_config: Optional. Set OpenAPI client configuration.
 46    """
 47
 48    @staticmethod
 49    def build(
 50        api_key: Optional[str] = None,
 51        host: Optional[str] = None,
 52        proxy_url: Optional[str] = None,
 53        proxy_headers: Optional[Dict[str, str]] = None,
 54        ssl_ca_certs: Optional[str] = None,
 55        ssl_verify: Optional[bool] = None,
 56        additional_headers: Optional[Dict[str, str]] = {},
 57        **kwargs,
 58    ) -> Config:
 59        api_key = api_key or kwargs.pop("api_key", None) or os.getenv("PINECONE_API_KEY")
 60        host = host or kwargs.pop("host", None)
 61        host = normalize_host(host)
 62        source_tag = kwargs.pop("source_tag", None)
 63
 64        if not api_key:
 65            raise PineconeConfigurationError(
 66                "You haven't specified an API key. Please either set the PINECONE_API_KEY environment variable or pass the 'api_key' keyword argument to the Pinecone client constructor."
 67            )
 68        if not host:
 69            raise PineconeConfigurationError("You haven't specified a host.")
 70
 71        return Config(
 72            api_key,
 73            host,
 74            proxy_url,
 75            proxy_headers,
 76            ssl_ca_certs,
 77            ssl_verify,
 78            additional_headers,
 79            source_tag,
 80        )
 81
 82    @staticmethod
 83    def build_openapi_config(
 84        config: Config, openapi_config: Optional[OpenApiConfiguration] = None, **kwargs
 85    ) -> OpenApiConfiguration:
 86        if openapi_config:
 87            openapi_config = OpenApiConfigFactory.copy(
 88                openapi_config=openapi_config, api_key=config.api_key, host=config.host
 89            )
 90        elif openapi_config is None:
 91            openapi_config = OpenApiConfigFactory.build(api_key=config.api_key, host=config.host)
 92
 93        # Check if value passed before overriding any values present
 94        # in the openapi_config. This means if the user has passed
 95        # an openapi_config object and a kwarg for the same setting,
 96        # the kwarg will take precedence.
 97        if config.proxy_url:
 98            openapi_config.proxy = config.proxy_url
 99        if config.proxy_headers:
100            openapi_config.proxy_headers = config.proxy_headers
101        if config.ssl_ca_certs:
102            openapi_config.ssl_ca_cert = config.ssl_ca_certs
103        if config.ssl_verify is not None:
104            openapi_config.verify_ssl = config.ssl_verify
105
106        return openapi_config
def normalize_host(host: Optional[str]) -> str:
11def normalize_host(host: Optional[str]) -> str:
12    if host is None:
13        return ""
14    if host.startswith("https://"):
15        return host
16    if host.startswith("http://"):
17        return host
18    return "https://" + host
class Config(typing.NamedTuple):
21class Config(NamedTuple):
22    api_key: str = ""
23    host: str = ""
24    proxy_url: Optional[str] = None
25    proxy_headers: Optional[Dict[str, str]] = None
26    ssl_ca_certs: Optional[str] = None
27    ssl_verify: Optional[bool] = None
28    additional_headers: Optional[Dict[str, str]] = {}
29    source_tag: Optional[str] = None

Config(api_key, host, proxy_url, proxy_headers, ssl_ca_certs, ssl_verify, additional_headers, source_tag)

Config( api_key: str = '', host: str = '', proxy_url: Optional[str] = None, proxy_headers: Optional[Dict[str, str]] = None, ssl_ca_certs: Optional[str] = None, ssl_verify: Optional[bool] = None, additional_headers: Optional[Dict[str, str]] = {}, source_tag: Optional[str] = None)

Create new instance of Config(api_key, host, proxy_url, proxy_headers, ssl_ca_certs, ssl_verify, additional_headers, source_tag)

api_key: str

Alias for field number 0

host: str

Alias for field number 1

proxy_url: Optional[str]

Alias for field number 2

proxy_headers: Optional[Dict[str, str]]

Alias for field number 3

ssl_ca_certs: Optional[str]

Alias for field number 4

ssl_verify: Optional[bool]

Alias for field number 5

additional_headers: Optional[Dict[str, str]]

Alias for field number 6

source_tag: Optional[str]

Alias for field number 7

Inherited Members
builtins.tuple
index
count
class ConfigBuilder:
 32class ConfigBuilder:
 33    """
 34
 35    Configurations are resolved in the following order:
 36
 37    - configs passed as keyword parameters
 38    - configs specified in environment variables
 39    - default values (if applicable)
 40    """
 41
 42    """Initializes the Pinecone client.
 43
 44    :param api_key: Required if not set in config file or by environment variable ``PINECONE_API_KEY``.
 45    :param host: Optional. Controller host.
 46    :param openapi_config: Optional. Set OpenAPI client configuration.
 47    """
 48
 49    @staticmethod
 50    def build(
 51        api_key: Optional[str] = None,
 52        host: Optional[str] = None,
 53        proxy_url: Optional[str] = None,
 54        proxy_headers: Optional[Dict[str, str]] = None,
 55        ssl_ca_certs: Optional[str] = None,
 56        ssl_verify: Optional[bool] = None,
 57        additional_headers: Optional[Dict[str, str]] = {},
 58        **kwargs,
 59    ) -> Config:
 60        api_key = api_key or kwargs.pop("api_key", None) or os.getenv("PINECONE_API_KEY")
 61        host = host or kwargs.pop("host", None)
 62        host = normalize_host(host)
 63        source_tag = kwargs.pop("source_tag", None)
 64
 65        if not api_key:
 66            raise PineconeConfigurationError(
 67                "You haven't specified an API key. Please either set the PINECONE_API_KEY environment variable or pass the 'api_key' keyword argument to the Pinecone client constructor."
 68            )
 69        if not host:
 70            raise PineconeConfigurationError("You haven't specified a host.")
 71
 72        return Config(
 73            api_key,
 74            host,
 75            proxy_url,
 76            proxy_headers,
 77            ssl_ca_certs,
 78            ssl_verify,
 79            additional_headers,
 80            source_tag,
 81        )
 82
 83    @staticmethod
 84    def build_openapi_config(
 85        config: Config, openapi_config: Optional[OpenApiConfiguration] = None, **kwargs
 86    ) -> OpenApiConfiguration:
 87        if openapi_config:
 88            openapi_config = OpenApiConfigFactory.copy(
 89                openapi_config=openapi_config, api_key=config.api_key, host=config.host
 90            )
 91        elif openapi_config is None:
 92            openapi_config = OpenApiConfigFactory.build(api_key=config.api_key, host=config.host)
 93
 94        # Check if value passed before overriding any values present
 95        # in the openapi_config. This means if the user has passed
 96        # an openapi_config object and a kwarg for the same setting,
 97        # the kwarg will take precedence.
 98        if config.proxy_url:
 99            openapi_config.proxy = config.proxy_url
100        if config.proxy_headers:
101            openapi_config.proxy_headers = config.proxy_headers
102        if config.ssl_ca_certs:
103            openapi_config.ssl_ca_cert = config.ssl_ca_certs
104        if config.ssl_verify is not None:
105            openapi_config.verify_ssl = config.ssl_verify
106
107        return openapi_config

Configurations are resolved in the following order:

  • configs passed as keyword parameters
  • configs specified in environment variables
  • default values (if applicable)
@staticmethod
def build( api_key: Optional[str] = None, host: Optional[str] = None, proxy_url: Optional[str] = None, proxy_headers: Optional[Dict[str, str]] = None, ssl_ca_certs: Optional[str] = None, ssl_verify: Optional[bool] = None, additional_headers: Optional[Dict[str, str]] = {}, **kwargs) -> Config:
49    @staticmethod
50    def build(
51        api_key: Optional[str] = None,
52        host: Optional[str] = None,
53        proxy_url: Optional[str] = None,
54        proxy_headers: Optional[Dict[str, str]] = None,
55        ssl_ca_certs: Optional[str] = None,
56        ssl_verify: Optional[bool] = None,
57        additional_headers: Optional[Dict[str, str]] = {},
58        **kwargs,
59    ) -> Config:
60        api_key = api_key or kwargs.pop("api_key", None) or os.getenv("PINECONE_API_KEY")
61        host = host or kwargs.pop("host", None)
62        host = normalize_host(host)
63        source_tag = kwargs.pop("source_tag", None)
64
65        if not api_key:
66            raise PineconeConfigurationError(
67                "You haven't specified an API key. Please either set the PINECONE_API_KEY environment variable or pass the 'api_key' keyword argument to the Pinecone client constructor."
68            )
69        if not host:
70            raise PineconeConfigurationError("You haven't specified a host.")
71
72        return Config(
73            api_key,
74            host,
75            proxy_url,
76            proxy_headers,
77            ssl_ca_certs,
78            ssl_verify,
79            additional_headers,
80            source_tag,
81        )
@staticmethod
def build_openapi_config( config: Config, openapi_config: Optional[pinecone.openapi_support.configuration.Configuration] = None, **kwargs) -> pinecone.openapi_support.configuration.Configuration:
 83    @staticmethod
 84    def build_openapi_config(
 85        config: Config, openapi_config: Optional[OpenApiConfiguration] = None, **kwargs
 86    ) -> OpenApiConfiguration:
 87        if openapi_config:
 88            openapi_config = OpenApiConfigFactory.copy(
 89                openapi_config=openapi_config, api_key=config.api_key, host=config.host
 90            )
 91        elif openapi_config is None:
 92            openapi_config = OpenApiConfigFactory.build(api_key=config.api_key, host=config.host)
 93
 94        # Check if value passed before overriding any values present
 95        # in the openapi_config. This means if the user has passed
 96        # an openapi_config object and a kwarg for the same setting,
 97        # the kwarg will take precedence.
 98        if config.proxy_url:
 99            openapi_config.proxy = config.proxy_url
100        if config.proxy_headers:
101            openapi_config.proxy_headers = config.proxy_headers
102        if config.ssl_ca_certs:
103            openapi_config.ssl_ca_cert = config.ssl_ca_certs
104        if config.ssl_verify is not None:
105            openapi_config.verify_ssl = config.ssl_verify
106
107        return openapi_config