contextbase-base-client 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. base_client/.fern/metadata.json +13 -0
  2. base_client/CONTRIBUTING.md +125 -0
  3. base_client/README.md +176 -0
  4. base_client/__init__.py +159 -0
  5. base_client/_default_clients.py +30 -0
  6. base_client/bases/__init__.py +34 -0
  7. base_client/bases/client.py +256 -0
  8. base_client/bases/raw_client.py +365 -0
  9. base_client/bases/types/__init__.py +34 -0
  10. base_client/bases/types/list_bases_response.py +20 -0
  11. base_client/binding_plan/__init__.py +4 -0
  12. base_client/binding_plan/client.py +108 -0
  13. base_client/binding_plan/raw_client.py +128 -0
  14. base_client/bindings/__init__.py +34 -0
  15. base_client/bindings/client.py +242 -0
  16. base_client/bindings/raw_client.py +326 -0
  17. base_client/bindings/types/__init__.py +34 -0
  18. base_client/bindings/types/list_bindings_response.py +20 -0
  19. base_client/client.py +252 -0
  20. base_client/core/__init__.py +127 -0
  21. base_client/core/api_error.py +23 -0
  22. base_client/core/client_wrapper.py +102 -0
  23. base_client/core/datetime_utils.py +70 -0
  24. base_client/core/file.py +67 -0
  25. base_client/core/force_multipart.py +18 -0
  26. base_client/core/http_client.py +839 -0
  27. base_client/core/http_response.py +59 -0
  28. base_client/core/http_sse/__init__.py +42 -0
  29. base_client/core/http_sse/_api.py +170 -0
  30. base_client/core/http_sse/_decoders.py +61 -0
  31. base_client/core/http_sse/_exceptions.py +7 -0
  32. base_client/core/http_sse/_models.py +17 -0
  33. base_client/core/jsonable_encoder.py +120 -0
  34. base_client/core/logging.py +107 -0
  35. base_client/core/parse_error.py +36 -0
  36. base_client/core/pydantic_utilities.py +508 -0
  37. base_client/core/query_encoder.py +58 -0
  38. base_client/core/remove_none_from_dict.py +11 -0
  39. base_client/core/request_options.py +35 -0
  40. base_client/core/serialization.py +347 -0
  41. base_client/dsn/__init__.py +4 -0
  42. base_client/dsn/client.py +104 -0
  43. base_client/dsn/raw_client.py +128 -0
  44. base_client/errors/__init__.py +38 -0
  45. base_client/errors/bad_request_error.py +11 -0
  46. base_client/errors/forbidden_error.py +11 -0
  47. base_client/reference.md +591 -0
  48. base_client/sync_state/__init__.py +34 -0
  49. base_client/sync_state/client.py +206 -0
  50. base_client/sync_state/raw_client.py +280 -0
  51. base_client/sync_state/types/__init__.py +34 -0
  52. base_client/sync_state/types/sync_state_input_bindings_value.py +23 -0
  53. base_client/tests/conftest.py +21 -0
  54. base_client/tests/test_aiohttp_autodetect.py +113 -0
  55. base_client/types/__init__.py +126 -0
  56. base_client/types/api_key_auth.py +19 -0
  57. base_client/types/authenticated_account_ref.py +20 -0
  58. base_client/types/base.py +23 -0
  59. base_client/types/binding.py +29 -0
  60. base_client/types/binding_auth.py +72 -0
  61. base_client/types/binding_auth_input.py +77 -0
  62. base_client/types/binding_auth_input_api_key.py +19 -0
  63. base_client/types/binding_auth_input_authenticated_account.py +20 -0
  64. base_client/types/binding_auth_input_client_credentials.py +20 -0
  65. base_client/types/binding_auth_input_none.py +17 -0
  66. base_client/types/binding_auth_none.py +17 -0
  67. base_client/types/binding_models.py +23 -0
  68. base_client/types/binding_state.py +24 -0
  69. base_client/types/binding_state_response.py +21 -0
  70. base_client/types/client_credentials_auth.py +20 -0
  71. base_client/types/dagster_all_plan_binding.py +27 -0
  72. base_client/types/dagster_all_plan_binding_mode.py +5 -0
  73. base_client/types/dagster_binding_plan_all.py +23 -0
  74. base_client/types/dsn_response.py +19 -0
  75. base_client/types/error.py +19 -0
  76. base_client/types/run_status.py +10 -0
  77. contextbase_base_client-0.5.0.dist-info/METADATA +10 -0
  78. contextbase_base_client-0.5.0.dist-info/RECORD +79 -0
  79. contextbase_base_client-0.5.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,127 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .api_error import ApiError
10
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
11
+ from .datetime_utils import Rfc2822DateTime, parse_rfc2822_datetime, serialize_datetime
12
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
13
+ from .http_client import AsyncHttpClient, HttpClient
14
+ from .http_response import AsyncHttpResponse, HttpResponse
15
+ from .jsonable_encoder import encode_path_param, jsonable_encoder
16
+ from .logging import ConsoleLogger, ILogger, LogConfig, LogLevel, Logger, create_logger
17
+ from .parse_error import ParsingError
18
+ from .pydantic_utilities import (
19
+ IS_PYDANTIC_V2,
20
+ UniversalBaseModel,
21
+ UniversalRootModel,
22
+ parse_obj_as,
23
+ universal_field_validator,
24
+ universal_root_validator,
25
+ update_forward_refs,
26
+ )
27
+ from .query_encoder import encode_query
28
+ from .remove_none_from_dict import remove_none_from_dict
29
+ from .request_options import RequestOptions
30
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
31
+ _dynamic_imports: typing.Dict[str, str] = {
32
+ "ApiError": ".api_error",
33
+ "AsyncClientWrapper": ".client_wrapper",
34
+ "AsyncHttpClient": ".http_client",
35
+ "AsyncHttpResponse": ".http_response",
36
+ "BaseClientWrapper": ".client_wrapper",
37
+ "ConsoleLogger": ".logging",
38
+ "FieldMetadata": ".serialization",
39
+ "File": ".file",
40
+ "HttpClient": ".http_client",
41
+ "HttpResponse": ".http_response",
42
+ "ILogger": ".logging",
43
+ "IS_PYDANTIC_V2": ".pydantic_utilities",
44
+ "LogConfig": ".logging",
45
+ "LogLevel": ".logging",
46
+ "Logger": ".logging",
47
+ "ParsingError": ".parse_error",
48
+ "RequestOptions": ".request_options",
49
+ "Rfc2822DateTime": ".datetime_utils",
50
+ "SyncClientWrapper": ".client_wrapper",
51
+ "UniversalBaseModel": ".pydantic_utilities",
52
+ "UniversalRootModel": ".pydantic_utilities",
53
+ "convert_and_respect_annotation_metadata": ".serialization",
54
+ "convert_file_dict_to_httpx_tuples": ".file",
55
+ "create_logger": ".logging",
56
+ "encode_path_param": ".jsonable_encoder",
57
+ "encode_query": ".query_encoder",
58
+ "jsonable_encoder": ".jsonable_encoder",
59
+ "parse_obj_as": ".pydantic_utilities",
60
+ "parse_rfc2822_datetime": ".datetime_utils",
61
+ "remove_none_from_dict": ".remove_none_from_dict",
62
+ "serialize_datetime": ".datetime_utils",
63
+ "universal_field_validator": ".pydantic_utilities",
64
+ "universal_root_validator": ".pydantic_utilities",
65
+ "update_forward_refs": ".pydantic_utilities",
66
+ "with_content_type": ".file",
67
+ }
68
+
69
+
70
+ def __getattr__(attr_name: str) -> typing.Any:
71
+ module_name = _dynamic_imports.get(attr_name)
72
+ if module_name is None:
73
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
74
+ try:
75
+ module = import_module(module_name, __package__)
76
+ if module_name == f".{attr_name}":
77
+ return module
78
+ else:
79
+ return getattr(module, attr_name)
80
+ except ImportError as e:
81
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
82
+ except AttributeError as e:
83
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
84
+
85
+
86
+ def __dir__():
87
+ lazy_attrs = list(_dynamic_imports.keys())
88
+ return sorted(lazy_attrs)
89
+
90
+
91
+ __all__ = [
92
+ "ApiError",
93
+ "AsyncClientWrapper",
94
+ "AsyncHttpClient",
95
+ "AsyncHttpResponse",
96
+ "BaseClientWrapper",
97
+ "ConsoleLogger",
98
+ "FieldMetadata",
99
+ "File",
100
+ "HttpClient",
101
+ "HttpResponse",
102
+ "ILogger",
103
+ "IS_PYDANTIC_V2",
104
+ "LogConfig",
105
+ "LogLevel",
106
+ "Logger",
107
+ "ParsingError",
108
+ "RequestOptions",
109
+ "Rfc2822DateTime",
110
+ "SyncClientWrapper",
111
+ "UniversalBaseModel",
112
+ "UniversalRootModel",
113
+ "convert_and_respect_annotation_metadata",
114
+ "convert_file_dict_to_httpx_tuples",
115
+ "create_logger",
116
+ "encode_path_param",
117
+ "encode_query",
118
+ "jsonable_encoder",
119
+ "parse_obj_as",
120
+ "parse_rfc2822_datetime",
121
+ "remove_none_from_dict",
122
+ "serialize_datetime",
123
+ "universal_field_validator",
124
+ "universal_root_validator",
125
+ "update_forward_refs",
126
+ "with_content_type",
127
+ ]
@@ -0,0 +1,23 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+
6
+ class ApiError(Exception):
7
+ headers: Optional[Dict[str, str]]
8
+ status_code: Optional[int]
9
+ body: Any
10
+
11
+ def __init__(
12
+ self,
13
+ *,
14
+ headers: Optional[Dict[str, str]] = None,
15
+ status_code: Optional[int] = None,
16
+ body: Any = None,
17
+ ) -> None:
18
+ self.headers = headers
19
+ self.status_code = status_code
20
+ self.body = body
21
+
22
+ def __str__(self) -> str:
23
+ return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
@@ -0,0 +1,102 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .http_client import AsyncHttpClient, HttpClient
7
+ from .logging import LogConfig, Logger
8
+
9
+
10
+ class BaseClientWrapper:
11
+ def __init__(
12
+ self,
13
+ *,
14
+ headers: typing.Optional[typing.Dict[str, str]] = None,
15
+ base_url: str,
16
+ timeout: typing.Optional[float] = None,
17
+ max_retries: int = 2,
18
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
19
+ ):
20
+ self._headers = headers
21
+ self._base_url = base_url
22
+ self._timeout = timeout
23
+ self._max_retries = max_retries
24
+ self._logging = logging
25
+
26
+ def get_headers(self) -> typing.Dict[str, str]:
27
+ import platform
28
+
29
+ headers: typing.Dict[str, str] = {
30
+ "User-Agent": "base_client/0.1.4",
31
+ "X-Fern-Language": "Python",
32
+ "X-Fern-Runtime": f"python/{platform.python_version()}",
33
+ "X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
34
+ **(self.get_custom_headers() or {}),
35
+ }
36
+ return headers
37
+
38
+ def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
39
+ return self._headers
40
+
41
+ def get_base_url(self) -> str:
42
+ return self._base_url
43
+
44
+ def get_timeout(self) -> typing.Optional[float]:
45
+ return self._timeout
46
+
47
+ def get_max_retries(self) -> int:
48
+ return self._max_retries
49
+
50
+
51
+ class SyncClientWrapper(BaseClientWrapper):
52
+ def __init__(
53
+ self,
54
+ *,
55
+ headers: typing.Optional[typing.Dict[str, str]] = None,
56
+ base_url: str,
57
+ timeout: typing.Optional[float] = None,
58
+ max_retries: int = 2,
59
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
60
+ httpx_client: httpx.Client,
61
+ ):
62
+ super().__init__(headers=headers, base_url=base_url, timeout=timeout, max_retries=max_retries, logging=logging)
63
+ self.httpx_client = HttpClient(
64
+ httpx_client=httpx_client,
65
+ base_headers=self.get_headers,
66
+ base_timeout=self.get_timeout,
67
+ base_url=self.get_base_url,
68
+ base_max_retries=self.get_max_retries(),
69
+ logging_config=self._logging,
70
+ )
71
+
72
+
73
+ class AsyncClientWrapper(BaseClientWrapper):
74
+ def __init__(
75
+ self,
76
+ *,
77
+ headers: typing.Optional[typing.Dict[str, str]] = None,
78
+ base_url: str,
79
+ timeout: typing.Optional[float] = None,
80
+ max_retries: int = 2,
81
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
82
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
83
+ httpx_client: httpx.AsyncClient,
84
+ ):
85
+ super().__init__(headers=headers, base_url=base_url, timeout=timeout, max_retries=max_retries, logging=logging)
86
+ self._async_token = async_token
87
+ self.httpx_client = AsyncHttpClient(
88
+ httpx_client=httpx_client,
89
+ base_headers=self.get_headers,
90
+ base_timeout=self.get_timeout,
91
+ base_url=self.get_base_url,
92
+ base_max_retries=self.get_max_retries(),
93
+ async_base_headers=self.async_get_headers,
94
+ logging_config=self._logging,
95
+ )
96
+
97
+ async def async_get_headers(self) -> typing.Dict[str, str]:
98
+ headers = self.get_headers()
99
+ if self._async_token is not None:
100
+ token = await self._async_token()
101
+ headers["Authorization"] = f"Bearer {token}"
102
+ return headers
@@ -0,0 +1,70 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+ from email.utils import parsedate_to_datetime
5
+ from typing import Any
6
+
7
+ import pydantic
8
+
9
+ IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
10
+
11
+
12
+ def parse_rfc2822_datetime(v: Any) -> dt.datetime:
13
+ """
14
+ Parse an RFC 2822 datetime string (e.g., "Wed, 02 Oct 2002 13:00:00 GMT")
15
+ into a datetime object. If the value is already a datetime, return it as-is.
16
+ Falls back to ISO 8601 parsing if RFC 2822 parsing fails.
17
+ """
18
+ if isinstance(v, dt.datetime):
19
+ return v
20
+ if isinstance(v, str):
21
+ try:
22
+ return parsedate_to_datetime(v)
23
+ except Exception:
24
+ pass
25
+ # Fallback to ISO 8601 parsing
26
+ return dt.datetime.fromisoformat(v.replace("Z", "+00:00"))
27
+ raise ValueError(f"Expected str or datetime, got {type(v)}")
28
+
29
+
30
+ class Rfc2822DateTime(dt.datetime):
31
+ """A datetime subclass that parses RFC 2822 date strings.
32
+
33
+ On Pydantic V1, uses __get_validators__ for pre-validation.
34
+ On Pydantic V2, uses __get_pydantic_core_schema__ for BeforeValidator-style parsing.
35
+ """
36
+
37
+ @classmethod
38
+ def __get_validators__(cls): # type: ignore[no-untyped-def]
39
+ yield parse_rfc2822_datetime
40
+
41
+ @classmethod
42
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> Any: # type: ignore[override]
43
+ from pydantic_core import core_schema
44
+
45
+ return core_schema.no_info_before_validator_function(parse_rfc2822_datetime, core_schema.datetime_schema())
46
+
47
+
48
+ def serialize_datetime(v: dt.datetime) -> str:
49
+ """
50
+ Serialize a datetime including timezone info.
51
+
52
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
53
+
54
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
55
+ """
56
+
57
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
58
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
59
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
60
+ return v.isoformat().replace("+00:00", "Z")
61
+ else:
62
+ # Delegate to the typical +/- offset format
63
+ return v.isoformat()
64
+
65
+ if v.tzinfo is not None:
66
+ return _serialize_zoned_datetime(v)
67
+ else:
68
+ local_tz = dt.datetime.now().astimezone().tzinfo
69
+ localized_dt = v.replace(tzinfo=local_tz)
70
+ return _serialize_zoned_datetime(localized_dt)
@@ -0,0 +1,67 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
4
+
5
+ # File typing inspired by the flexibility of types within the httpx library
6
+ # https://github.com/encode/httpx/blob/master/httpx/_types.py
7
+ FileContent = Union[IO[bytes], bytes, str]
8
+ File = Union[
9
+ # file (or bytes)
10
+ FileContent,
11
+ # (filename, file (or bytes))
12
+ Tuple[Optional[str], FileContent],
13
+ # (filename, file (or bytes), content_type)
14
+ Tuple[Optional[str], FileContent, Optional[str]],
15
+ # (filename, file (or bytes), content_type, headers)
16
+ Tuple[
17
+ Optional[str],
18
+ FileContent,
19
+ Optional[str],
20
+ Mapping[str, str],
21
+ ],
22
+ ]
23
+
24
+
25
+ def convert_file_dict_to_httpx_tuples(
26
+ d: Dict[str, Union[File, List[File]]],
27
+ ) -> List[Tuple[str, File]]:
28
+ """
29
+ The format we use is a list of tuples, where the first element is the
30
+ name of the file and the second is the file object. Typically HTTPX wants
31
+ a dict, but to be able to send lists of files, you have to use the list
32
+ approach (which also works for non-lists)
33
+ https://github.com/encode/httpx/pull/1032
34
+ """
35
+
36
+ httpx_tuples = []
37
+ for key, file_like in d.items():
38
+ if isinstance(file_like, list):
39
+ for file_like_item in file_like:
40
+ httpx_tuples.append((key, file_like_item))
41
+ else:
42
+ httpx_tuples.append((key, file_like))
43
+ return httpx_tuples
44
+
45
+
46
+ def with_content_type(*, file: File, default_content_type: str) -> File:
47
+ """
48
+ This function resolves to the file's content type, if provided, and defaults
49
+ to the default_content_type value if not.
50
+ """
51
+ if isinstance(file, tuple):
52
+ if len(file) == 2:
53
+ filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
54
+ return (filename, content, default_content_type)
55
+ elif len(file) == 3:
56
+ filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
57
+ out_content_type = file_content_type or default_content_type
58
+ return (filename, content, out_content_type)
59
+ elif len(file) == 4:
60
+ filename, content, file_content_type, headers = cast( # type: ignore
61
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
62
+ )
63
+ out_content_type = file_content_type or default_content_type
64
+ return (filename, content, out_content_type, headers)
65
+ else:
66
+ raise ValueError(f"Unexpected tuple length: {len(file)}")
67
+ return (None, file, default_content_type)
@@ -0,0 +1,18 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict
4
+
5
+
6
+ class ForceMultipartDict(Dict[str, Any]):
7
+ """
8
+ A dictionary subclass that always evaluates to True in boolean contexts.
9
+
10
+ This is used to force multipart/form-data encoding in HTTP requests even when
11
+ the dictionary is empty, which would normally evaluate to False.
12
+ """
13
+
14
+ def __bool__(self) -> bool:
15
+ return True
16
+
17
+
18
+ FORCE_MULTIPART = ForceMultipartDict()