permitstack 1.0.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 (68) hide show
  1. permitstack/__init__.py +17 -0
  2. permitstack/_hooks/__init__.py +4 -0
  3. permitstack/_hooks/sdkhooks.py +74 -0
  4. permitstack/_hooks/types.py +112 -0
  5. permitstack/_version.py +15 -0
  6. permitstack/basesdk.py +396 -0
  7. permitstack/bulk_export.py +241 -0
  8. permitstack/contractors.py +625 -0
  9. permitstack/errors/__init__.py +39 -0
  10. permitstack/errors/httpvalidationerror.py +28 -0
  11. permitstack/errors/no_response_error.py +17 -0
  12. permitstack/errors/permitstackdefaulterror.py +40 -0
  13. permitstack/errors/permitstackerror.py +30 -0
  14. permitstack/errors/responsevalidationerror.py +27 -0
  15. permitstack/health.py +171 -0
  16. permitstack/httpclient.py +125 -0
  17. permitstack/models/__init__.py +158 -0
  18. permitstack/models/contractorprofile.py +108 -0
  19. permitstack/models/contractorsearchresponse.py +24 -0
  20. permitstack/models/contractorsummary.py +57 -0
  21. permitstack/models/delete_webhookop.py +16 -0
  22. permitstack/models/export_permits_csvop.py +98 -0
  23. permitstack/models/get_contractor_permitsop.py +46 -0
  24. permitstack/models/get_contractorop.py +16 -0
  25. permitstack/models/get_permitop.py +16 -0
  26. permitstack/models/get_permits_by_addressop.py +46 -0
  27. permitstack/models/get_property_historyop.py +18 -0
  28. permitstack/models/permitcategory.py +27 -0
  29. permitstack/models/permitdetail.py +164 -0
  30. permitstack/models/permitsearchresponse.py +24 -0
  31. permitstack/models/permitstatus.py +16 -0
  32. permitstack/models/permitsummary.py +121 -0
  33. permitstack/models/propertytype.py +14 -0
  34. permitstack/models/search_contractorsop.py +98 -0
  35. permitstack/models/search_permitsop.py +247 -0
  36. permitstack/models/security.py +42 -0
  37. permitstack/models/validationerror.py +57 -0
  38. permitstack/models/webhookcreate.py +60 -0
  39. permitstack/permits.py +866 -0
  40. permitstack/property_history.py +207 -0
  41. permitstack/py.typed +1 -0
  42. permitstack/sdk.py +218 -0
  43. permitstack/sdkconfiguration.py +49 -0
  44. permitstack/types/__init__.py +21 -0
  45. permitstack/types/basemodel.py +77 -0
  46. permitstack/utils/__init__.py +178 -0
  47. permitstack/utils/annotations.py +79 -0
  48. permitstack/utils/datetimes.py +23 -0
  49. permitstack/utils/dynamic_imports.py +54 -0
  50. permitstack/utils/enums.py +134 -0
  51. permitstack/utils/eventstreaming.py +309 -0
  52. permitstack/utils/forms.py +234 -0
  53. permitstack/utils/headers.py +136 -0
  54. permitstack/utils/logger.py +27 -0
  55. permitstack/utils/metadata.py +119 -0
  56. permitstack/utils/queryparams.py +217 -0
  57. permitstack/utils/requestbodies.py +66 -0
  58. permitstack/utils/retries.py +271 -0
  59. permitstack/utils/security.py +215 -0
  60. permitstack/utils/serializers.py +225 -0
  61. permitstack/utils/unmarshal_json_response.py +38 -0
  62. permitstack/utils/url.py +155 -0
  63. permitstack/utils/values.py +137 -0
  64. permitstack/webhooks.py +593 -0
  65. permitstack-1.0.0.dist-info/METADATA +541 -0
  66. permitstack-1.0.0.dist-info/RECORD +68 -0
  67. permitstack-1.0.0.dist-info/WHEEL +5 -0
  68. permitstack-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,207 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from permitstack import errors, models, utils
5
+ from permitstack._hooks import HookContext
6
+ from permitstack.types import OptionalNullable, UNSET
7
+ from permitstack.utils import get_security_from_env
8
+ from permitstack.utils.unmarshal_json_response import unmarshal_json_response
9
+ from typing import Any, Mapping, Optional
10
+
11
+
12
+ class PropertyHistory(BaseSDK):
13
+ r"""Get permit history for a specific address"""
14
+
15
+ def get_property_history(
16
+ self,
17
+ *,
18
+ address: str,
19
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
20
+ server_url: Optional[str] = None,
21
+ timeout_ms: Optional[int] = None,
22
+ http_headers: Optional[Mapping[str, str]] = None,
23
+ ) -> Any:
24
+ r"""Get Property History
25
+
26
+ Get the complete construction history for a property address.
27
+
28
+ Returns all permits ever filed at or near this address, sorted by date.
29
+ Useful for insurance underwriting, real estate due diligence, and property valuation.
30
+
31
+ :param address: Street address to look up
32
+ :param retries: Override the default retry configuration for this method
33
+ :param server_url: Override the default server URL for this method
34
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
35
+ :param http_headers: Additional headers to set or replace on requests.
36
+ """
37
+ base_url = None
38
+ url_variables = None
39
+ if timeout_ms is None:
40
+ timeout_ms = self.sdk_configuration.timeout_ms
41
+
42
+ if server_url is not None:
43
+ base_url = server_url
44
+ else:
45
+ base_url = self._get_url(base_url, url_variables)
46
+
47
+ request = models.GetPropertyHistoryRequest(
48
+ address=address,
49
+ )
50
+
51
+ req = self._build_request(
52
+ method="GET",
53
+ path="/v1/property/history",
54
+ base_url=base_url,
55
+ url_variables=url_variables,
56
+ request=request,
57
+ request_body_required=False,
58
+ request_has_path_params=False,
59
+ request_has_query_params=True,
60
+ user_agent_header="user-agent",
61
+ accept_header_value="application/json",
62
+ http_headers=http_headers,
63
+ security=self.sdk_configuration.security,
64
+ allow_empty_value=None,
65
+ timeout_ms=timeout_ms,
66
+ )
67
+
68
+ if retries == UNSET:
69
+ if self.sdk_configuration.retry_config is not UNSET:
70
+ retries = self.sdk_configuration.retry_config
71
+
72
+ retry_config = None
73
+ if isinstance(retries, utils.RetryConfig):
74
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
75
+
76
+ http_res = self.do_request(
77
+ hook_ctx=HookContext(
78
+ config=self.sdk_configuration,
79
+ base_url=base_url or "",
80
+ operation_id="get_property_history",
81
+ oauth2_scopes=None,
82
+ security_source=get_security_from_env(
83
+ self.sdk_configuration.security, models.Security
84
+ ),
85
+ ),
86
+ request=req,
87
+ is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
88
+ retry_config=retry_config,
89
+ )
90
+
91
+ response_data: Any = None
92
+ if utils.match_response(http_res, "200", "application/json"):
93
+ return unmarshal_json_response(Any, http_res)
94
+ if utils.match_response(http_res, "422", "application/json"):
95
+ response_data = unmarshal_json_response(
96
+ errors.HTTPValidationErrorData, http_res
97
+ )
98
+ raise errors.HTTPValidationError(response_data, http_res)
99
+ if utils.match_response(http_res, "4XX", "*"):
100
+ http_res_text = utils.stream_to_text(http_res)
101
+ raise errors.PermitstackDefaultError(
102
+ "API error occurred", http_res, http_res_text
103
+ )
104
+ if utils.match_response(http_res, "5XX", "*"):
105
+ http_res_text = utils.stream_to_text(http_res)
106
+ raise errors.PermitstackDefaultError(
107
+ "API error occurred", http_res, http_res_text
108
+ )
109
+
110
+ raise errors.PermitstackDefaultError("Unexpected response received", http_res)
111
+
112
+ async def get_property_history_async(
113
+ self,
114
+ *,
115
+ address: str,
116
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
117
+ server_url: Optional[str] = None,
118
+ timeout_ms: Optional[int] = None,
119
+ http_headers: Optional[Mapping[str, str]] = None,
120
+ ) -> Any:
121
+ r"""Get Property History
122
+
123
+ Get the complete construction history for a property address.
124
+
125
+ Returns all permits ever filed at or near this address, sorted by date.
126
+ Useful for insurance underwriting, real estate due diligence, and property valuation.
127
+
128
+ :param address: Street address to look up
129
+ :param retries: Override the default retry configuration for this method
130
+ :param server_url: Override the default server URL for this method
131
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
132
+ :param http_headers: Additional headers to set or replace on requests.
133
+ """
134
+ base_url = None
135
+ url_variables = None
136
+ if timeout_ms is None:
137
+ timeout_ms = self.sdk_configuration.timeout_ms
138
+
139
+ if server_url is not None:
140
+ base_url = server_url
141
+ else:
142
+ base_url = self._get_url(base_url, url_variables)
143
+
144
+ request = models.GetPropertyHistoryRequest(
145
+ address=address,
146
+ )
147
+
148
+ req = self._build_request_async(
149
+ method="GET",
150
+ path="/v1/property/history",
151
+ base_url=base_url,
152
+ url_variables=url_variables,
153
+ request=request,
154
+ request_body_required=False,
155
+ request_has_path_params=False,
156
+ request_has_query_params=True,
157
+ user_agent_header="user-agent",
158
+ accept_header_value="application/json",
159
+ http_headers=http_headers,
160
+ security=self.sdk_configuration.security,
161
+ allow_empty_value=None,
162
+ timeout_ms=timeout_ms,
163
+ )
164
+
165
+ if retries == UNSET:
166
+ if self.sdk_configuration.retry_config is not UNSET:
167
+ retries = self.sdk_configuration.retry_config
168
+
169
+ retry_config = None
170
+ if isinstance(retries, utils.RetryConfig):
171
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
172
+
173
+ http_res = await self.do_request_async(
174
+ hook_ctx=HookContext(
175
+ config=self.sdk_configuration,
176
+ base_url=base_url or "",
177
+ operation_id="get_property_history",
178
+ oauth2_scopes=None,
179
+ security_source=get_security_from_env(
180
+ self.sdk_configuration.security, models.Security
181
+ ),
182
+ ),
183
+ request=req,
184
+ is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
185
+ retry_config=retry_config,
186
+ )
187
+
188
+ response_data: Any = None
189
+ if utils.match_response(http_res, "200", "application/json"):
190
+ return unmarshal_json_response(Any, http_res)
191
+ if utils.match_response(http_res, "422", "application/json"):
192
+ response_data = unmarshal_json_response(
193
+ errors.HTTPValidationErrorData, http_res
194
+ )
195
+ raise errors.HTTPValidationError(response_data, http_res)
196
+ if utils.match_response(http_res, "4XX", "*"):
197
+ http_res_text = await utils.stream_to_text_async(http_res)
198
+ raise errors.PermitstackDefaultError(
199
+ "API error occurred", http_res, http_res_text
200
+ )
201
+ if utils.match_response(http_res, "5XX", "*"):
202
+ http_res_text = await utils.stream_to_text_async(http_res)
203
+ raise errors.PermitstackDefaultError(
204
+ "API error occurred", http_res, http_res_text
205
+ )
206
+
207
+ raise errors.PermitstackDefaultError("Unexpected response received", http_res)
permitstack/py.typed ADDED
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561. The package enables type hints.
permitstack/sdk.py ADDED
@@ -0,0 +1,218 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from .httpclient import AsyncHttpClient, ClientOwner, HttpClient, close_clients
5
+ from .sdkconfiguration import SDKConfiguration
6
+ from .utils.logger import Logger, get_default_logger
7
+ from .utils.retries import RetryConfig
8
+ import httpx
9
+ import importlib
10
+ from permitstack import models, utils
11
+ from permitstack._hooks import SDKHooks
12
+ from permitstack.types import OptionalNullable, UNSET
13
+ import sys
14
+ from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast
15
+ import weakref
16
+
17
+ if TYPE_CHECKING:
18
+ from permitstack.bulk_export import BulkExport
19
+ from permitstack.contractors import Contractors
20
+ from permitstack.health import Health
21
+ from permitstack.permits import Permits
22
+ from permitstack.property_history import PropertyHistory
23
+ from permitstack.webhooks import Webhooks
24
+
25
+
26
+ class Permitstack(BaseSDK):
27
+ r"""PermitStack:
28
+ ## PermitStack Building Permit API
29
+
30
+ Access 15.59M+ building permits across 54 U.S. cities and counties, updated daily from official open data portals.
31
+
32
+ ### Getting started
33
+ 1. Sign up at [permit-stack.com](https://permit-stack.com/#pricing) for a free API key (1,000 req/day)
34
+ 2. Pass your key as `X-API-Key` header on every request
35
+ 3. See the `/v1/permits/search` endpoint to get started
36
+
37
+ ### Rate limits
38
+ Tier | Requests/min | Requests/day
39
+ -----------|--------------|-------------
40
+ Free | 30 | 1,000
41
+ Developer | 60 | 10,000
42
+ Startup | 200 | 100,000
43
+ Growth | 500 | 500,000
44
+
45
+ ### Support
46
+ support@aisaasfactory.io
47
+
48
+ """
49
+
50
+ health: "Health"
51
+ r"""Service health checks"""
52
+ permits: "Permits"
53
+ r"""Search and retrieve building permits"""
54
+ contractors: "Contractors"
55
+ r"""Search contractors and see their permit history"""
56
+ property_history: "PropertyHistory"
57
+ r"""Get permit history for a specific address"""
58
+ bulk_export: "BulkExport"
59
+ r"""Export permit data in bulk (CSV)"""
60
+ webhooks: "Webhooks"
61
+ r"""Subscribe to real-time permit events (paid tiers)"""
62
+ _sub_sdk_map = {
63
+ "health": ("permitstack.health", "Health"),
64
+ "permits": ("permitstack.permits", "Permits"),
65
+ "contractors": ("permitstack.contractors", "Contractors"),
66
+ "property_history": ("permitstack.property_history", "PropertyHistory"),
67
+ "bulk_export": ("permitstack.bulk_export", "BulkExport"),
68
+ "webhooks": ("permitstack.webhooks", "Webhooks"),
69
+ }
70
+
71
+ def __init__(
72
+ self,
73
+ api_key: Optional[Union[Optional[str], Callable[[], Optional[str]]]] = None,
74
+ server_idx: Optional[int] = None,
75
+ url_params: Optional[Dict[str, str]] = None,
76
+ server_url: Optional[str] = None,
77
+ client: Optional[HttpClient] = None,
78
+ async_client: Optional[AsyncHttpClient] = None,
79
+ retry_config: OptionalNullable[RetryConfig] = UNSET,
80
+ timeout_ms: Optional[int] = None,
81
+ debug_logger: Optional[Logger] = None,
82
+ ) -> None:
83
+ r"""Instantiates the SDK configuring it with the provided parameters.
84
+
85
+ :param api_key: The api_key required for authentication
86
+ :param server_idx: The index of the server to use for all methods
87
+ :param server_url: The server URL to use for all methods
88
+ :param url_params: Parameters to optionally template the server URL with
89
+ :param client: The HTTP client to use for all synchronous methods
90
+ :param async_client: The Async HTTP client to use for all asynchronous methods
91
+ :param retry_config: The retry configuration to use for all supported methods
92
+ :param timeout_ms: Optional request timeout applied to each operation in milliseconds
93
+ """
94
+ client_supplied = True
95
+ if client is None:
96
+ client = httpx.Client(follow_redirects=True)
97
+ client_supplied = False
98
+
99
+ assert issubclass(
100
+ type(client), HttpClient
101
+ ), "The provided client must implement the HttpClient protocol."
102
+
103
+ async_client_supplied = True
104
+ if async_client is None:
105
+ async_client = httpx.AsyncClient(follow_redirects=True)
106
+ async_client_supplied = False
107
+
108
+ if debug_logger is None:
109
+ debug_logger = get_default_logger()
110
+
111
+ assert issubclass(
112
+ type(async_client), AsyncHttpClient
113
+ ), "The provided async_client must implement the AsyncHttpClient protocol."
114
+
115
+ security: Any = None
116
+ if callable(api_key):
117
+ # pylint: disable=unnecessary-lambda-assignment
118
+ security = lambda: models.Security(api_key=api_key())
119
+ else:
120
+ security = models.Security(api_key=api_key)
121
+
122
+ if server_url is not None:
123
+ if url_params is not None:
124
+ server_url = utils.template_url(server_url, url_params)
125
+
126
+ BaseSDK.__init__(
127
+ self,
128
+ SDKConfiguration(
129
+ client=client,
130
+ client_supplied=client_supplied,
131
+ async_client=async_client,
132
+ async_client_supplied=async_client_supplied,
133
+ security=security,
134
+ server_url=server_url,
135
+ server_idx=server_idx,
136
+ retry_config=retry_config,
137
+ timeout_ms=timeout_ms,
138
+ debug_logger=debug_logger,
139
+ ),
140
+ parent_ref=self,
141
+ )
142
+
143
+ hooks = SDKHooks()
144
+
145
+ # pylint: disable=protected-access
146
+ self.sdk_configuration.__dict__["_hooks"] = hooks
147
+
148
+ self.sdk_configuration = hooks.sdk_init(self.sdk_configuration)
149
+
150
+ weakref.finalize(
151
+ self,
152
+ close_clients,
153
+ cast(ClientOwner, self.sdk_configuration),
154
+ self.sdk_configuration.client,
155
+ self.sdk_configuration.client_supplied,
156
+ self.sdk_configuration.async_client,
157
+ self.sdk_configuration.async_client_supplied,
158
+ )
159
+
160
+ def dynamic_import(self, modname, retries=3):
161
+ for attempt in range(retries):
162
+ try:
163
+ return importlib.import_module(modname)
164
+ except KeyError:
165
+ # Clear any half-initialized module and retry
166
+ sys.modules.pop(modname, None)
167
+ if attempt == retries - 1:
168
+ break
169
+ raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
170
+
171
+ def __getattr__(self, name: str):
172
+ if name in self._sub_sdk_map:
173
+ module_path, class_name = self._sub_sdk_map[name]
174
+ try:
175
+ module = self.dynamic_import(module_path)
176
+ klass = getattr(module, class_name)
177
+ instance = klass(self.sdk_configuration, parent_ref=self)
178
+ setattr(self, name, instance)
179
+ return instance
180
+ except ImportError as e:
181
+ raise AttributeError(
182
+ f"Failed to import module {module_path} for attribute {name}: {e}"
183
+ ) from e
184
+ except AttributeError as e:
185
+ raise AttributeError(
186
+ f"Failed to find class {class_name} in module {module_path} for attribute {name}: {e}"
187
+ ) from e
188
+
189
+ raise AttributeError(
190
+ f"'{type(self).__name__}' object has no attribute '{name}'"
191
+ )
192
+
193
+ def __dir__(self):
194
+ default_attrs = list(super().__dir__())
195
+ lazy_attrs = list(self._sub_sdk_map.keys())
196
+ return sorted(list(set(default_attrs + lazy_attrs)))
197
+
198
+ def __enter__(self):
199
+ return self
200
+
201
+ async def __aenter__(self):
202
+ return self
203
+
204
+ def __exit__(self, exc_type, exc_val, exc_tb):
205
+ if (
206
+ self.sdk_configuration.client is not None
207
+ and not self.sdk_configuration.client_supplied
208
+ ):
209
+ self.sdk_configuration.client.close()
210
+ self.sdk_configuration.client = None
211
+
212
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
213
+ if (
214
+ self.sdk_configuration.async_client is not None
215
+ and not self.sdk_configuration.async_client_supplied
216
+ ):
217
+ await self.sdk_configuration.async_client.aclose()
218
+ self.sdk_configuration.async_client = None
@@ -0,0 +1,49 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from ._version import (
4
+ __gen_version__,
5
+ __openapi_doc_version__,
6
+ __user_agent__,
7
+ __version__,
8
+ )
9
+ from .httpclient import AsyncHttpClient, HttpClient
10
+ from .utils import Logger, RetryConfig, remove_suffix
11
+ from dataclasses import dataclass
12
+ from permitstack import models
13
+ from permitstack.types import OptionalNullable, UNSET
14
+ from pydantic import Field
15
+ from typing import Callable, Dict, Optional, Tuple, Union
16
+
17
+
18
+ SERVERS = [
19
+ "https://api.permit-stack.com",
20
+ # Production
21
+ ]
22
+ """Contains the list of servers available to the SDK"""
23
+
24
+
25
+ @dataclass
26
+ class SDKConfiguration:
27
+ client: Union[HttpClient, None]
28
+ client_supplied: bool
29
+ async_client: Union[AsyncHttpClient, None]
30
+ async_client_supplied: bool
31
+ debug_logger: Logger
32
+ security: Optional[Union[models.Security, Callable[[], models.Security]]] = None
33
+ server_url: Optional[str] = ""
34
+ server_idx: Optional[int] = 0
35
+ language: str = "python"
36
+ openapi_doc_version: str = __openapi_doc_version__
37
+ sdk_version: str = __version__
38
+ gen_version: str = __gen_version__
39
+ user_agent: str = __user_agent__
40
+ retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
41
+ timeout_ms: Optional[int] = None
42
+
43
+ def get_server_details(self) -> Tuple[str, Dict[str, str]]:
44
+ if self.server_url is not None and self.server_url:
45
+ return remove_suffix(self.server_url, "/"), {}
46
+ if self.server_idx is None:
47
+ self.server_idx = 0
48
+
49
+ return SERVERS[self.server_idx], {}
@@ -0,0 +1,21 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basemodel import (
4
+ BaseModel,
5
+ Nullable,
6
+ OptionalNullable,
7
+ UnrecognizedInt,
8
+ UnrecognizedStr,
9
+ UNSET,
10
+ UNSET_SENTINEL,
11
+ )
12
+
13
+ __all__ = [
14
+ "BaseModel",
15
+ "Nullable",
16
+ "OptionalNullable",
17
+ "UnrecognizedInt",
18
+ "UnrecognizedStr",
19
+ "UNSET",
20
+ "UNSET_SENTINEL",
21
+ ]
@@ -0,0 +1,77 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from pydantic import ConfigDict, model_serializer
4
+ from pydantic import BaseModel as PydanticBaseModel
5
+ from pydantic_core import core_schema
6
+ from typing import TYPE_CHECKING, Any, Literal, Optional, TypeVar, Union
7
+ from typing_extensions import TypeAliasType, TypeAlias
8
+
9
+
10
+ class BaseModel(PydanticBaseModel):
11
+ model_config = ConfigDict(
12
+ populate_by_name=True, arbitrary_types_allowed=True, protected_namespaces=()
13
+ )
14
+
15
+
16
+ class Unset(BaseModel):
17
+ @model_serializer(mode="plain")
18
+ def serialize_model(self):
19
+ return UNSET_SENTINEL
20
+
21
+ def __bool__(self) -> Literal[False]:
22
+ return False
23
+
24
+
25
+ UNSET = Unset()
26
+ UNSET_SENTINEL = "~?~unset~?~sentinel~?~"
27
+
28
+
29
+ T = TypeVar("T")
30
+ if TYPE_CHECKING:
31
+ Nullable: TypeAlias = Union[T, None]
32
+ OptionalNullable: TypeAlias = Union[Optional[Nullable[T]], Unset]
33
+ else:
34
+ Nullable = TypeAliasType("Nullable", Union[T, None], type_params=(T,))
35
+ OptionalNullable = TypeAliasType(
36
+ "OptionalNullable", Union[Optional[Nullable[T]], Unset], type_params=(T,)
37
+ )
38
+
39
+
40
+ class UnrecognizedStr(str):
41
+ @classmethod
42
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
43
+ # Make UnrecognizedStr only work in lax mode, not strict mode
44
+ # This makes it a "fallback" option when more specific types (like Literals) don't match
45
+ def validate_lax(v: Any) -> 'UnrecognizedStr':
46
+ if isinstance(v, cls):
47
+ return v
48
+ return cls(str(v))
49
+
50
+ # Use lax_or_strict_schema where strict always fails
51
+ # This forces Pydantic to prefer other union members in strict mode
52
+ # and only fall back to UnrecognizedStr in lax mode
53
+ return core_schema.lax_or_strict_schema(
54
+ lax_schema=core_schema.chain_schema([
55
+ core_schema.str_schema(),
56
+ core_schema.no_info_plain_validator_function(validate_lax)
57
+ ]),
58
+ strict_schema=core_schema.none_schema(), # Always fails in strict mode
59
+ )
60
+
61
+
62
+ class UnrecognizedInt(int):
63
+ @classmethod
64
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
65
+ # Make UnrecognizedInt only work in lax mode, not strict mode
66
+ # This makes it a "fallback" option when more specific types (like Literals) don't match
67
+ def validate_lax(v: Any) -> 'UnrecognizedInt':
68
+ if isinstance(v, cls):
69
+ return v
70
+ return cls(int(v))
71
+ return core_schema.lax_or_strict_schema(
72
+ lax_schema=core_schema.chain_schema([
73
+ core_schema.int_schema(),
74
+ core_schema.no_info_plain_validator_function(validate_lax)
75
+ ]),
76
+ strict_schema=core_schema.none_schema(), # Always fails in strict mode
77
+ )