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