ab-client-token-validator 0.1.0__tar.gz

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.
@@ -0,0 +1,23 @@
1
+ __pycache__/
2
+ build/
3
+ dist/
4
+ *.egg-info/
5
+ .pytest_cache/
6
+
7
+ # pyenv
8
+ .python-version
9
+
10
+ # Environments
11
+ .env
12
+ .venv
13
+
14
+ # mypy
15
+ .mypy_cache/
16
+ .dmypy.json
17
+ dmypy.json
18
+
19
+ # JetBrains
20
+ .idea/
21
+
22
+ /coverage.xml
23
+ /.coverage
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: ab-client-token-validator
3
+ Version: 0.1.0
4
+ Summary: A client library for accessing FastAPI
5
+ Requires-Python: ~=3.9
6
+ Requires-Dist: attrs>=22.2.0
7
+ Requires-Dist: httpx<0.29.0,>=0.23.0
8
+ Requires-Dist: python-dateutil<3,>=2.8.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # ab-client-token-validator
12
+ A client library for accessing FastAPI
13
+
14
+ ## Usage
15
+ First, create a client:
16
+
17
+ ```python
18
+ from ab_client_token_validator import Client
19
+
20
+ client = Client(base_url="https://api.example.com")
21
+ ```
22
+
23
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
24
+
25
+ ```python
26
+ from ab_client_token_validator import AuthenticatedClient
27
+
28
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
29
+ ```
30
+
31
+ Now call your endpoint and use your models:
32
+
33
+ ```python
34
+ from ab_client_token_validator.models import MyDataModel
35
+ from ab_client_token_validator.api.my_tag import get_my_data_model
36
+ from ab_client_token_validator.types import Response
37
+
38
+ with client as client:
39
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
40
+ # or if you need more info (e.g. status_code)
41
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
42
+ ```
43
+
44
+ Or do the same thing with an async version:
45
+
46
+ ```python
47
+ from ab_client_token_validator.models import MyDataModel
48
+ from ab_client_token_validator.api.my_tag import get_my_data_model
49
+ from ab_client_token_validator.types import Response
50
+
51
+ async with client as client:
52
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
53
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
54
+ ```
55
+
56
+ By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
57
+
58
+ ```python
59
+ client = AuthenticatedClient(
60
+ base_url="https://internal_api.example.com",
61
+ token="SuperSecretToken",
62
+ verify_ssl="/path/to/certificate_bundle.pem",
63
+ )
64
+ ```
65
+
66
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
67
+
68
+ ```python
69
+ client = AuthenticatedClient(
70
+ base_url="https://internal_api.example.com",
71
+ token="SuperSecretToken",
72
+ verify_ssl=False
73
+ )
74
+ ```
75
+
76
+ Things to know:
77
+ 1. Every path/method combo becomes a Python module with four functions:
78
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
79
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
80
+ 1. `asyncio`: Like `sync` but async instead of blocking
81
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
82
+
83
+ 1. All path/query params, and bodies become method arguments.
84
+ 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
85
+ 1. Any endpoint which did not have a tag will be in `ab_client_token_validator.api.default`
86
+
87
+ ## Advanced customizations
88
+
89
+ There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
90
+
91
+ ```python
92
+ from ab_client_token_validator import Client
93
+
94
+ def log_request(request):
95
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
96
+
97
+ def log_response(response):
98
+ request = response.request
99
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
100
+
101
+ client = Client(
102
+ base_url="https://api.example.com",
103
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
104
+ )
105
+
106
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
107
+ ```
108
+
109
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
110
+
111
+ ```python
112
+ import httpx
113
+ from ab_client_token_validator import Client
114
+
115
+ client = Client(
116
+ base_url="https://api.example.com",
117
+ )
118
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
119
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
120
+ ```
121
+
122
+ ## Building / publishing this package
123
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
124
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
125
+ 1. If you're using a private repository, configure it with Poetry
126
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
127
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
128
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
129
+
130
+ If you want to install this client into another project without publishing it (e.g. for development) then:
131
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
132
+ 1. If that project is not using Poetry:
133
+ 1. Build a wheel with `poetry build -f wheel`
134
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
@@ -0,0 +1,124 @@
1
+ # ab-client-token-validator
2
+ A client library for accessing FastAPI
3
+
4
+ ## Usage
5
+ First, create a client:
6
+
7
+ ```python
8
+ from ab_client_token_validator import Client
9
+
10
+ client = Client(base_url="https://api.example.com")
11
+ ```
12
+
13
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
14
+
15
+ ```python
16
+ from ab_client_token_validator import AuthenticatedClient
17
+
18
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
19
+ ```
20
+
21
+ Now call your endpoint and use your models:
22
+
23
+ ```python
24
+ from ab_client_token_validator.models import MyDataModel
25
+ from ab_client_token_validator.api.my_tag import get_my_data_model
26
+ from ab_client_token_validator.types import Response
27
+
28
+ with client as client:
29
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
30
+ # or if you need more info (e.g. status_code)
31
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
32
+ ```
33
+
34
+ Or do the same thing with an async version:
35
+
36
+ ```python
37
+ from ab_client_token_validator.models import MyDataModel
38
+ from ab_client_token_validator.api.my_tag import get_my_data_model
39
+ from ab_client_token_validator.types import Response
40
+
41
+ async with client as client:
42
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
43
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
44
+ ```
45
+
46
+ By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
47
+
48
+ ```python
49
+ client = AuthenticatedClient(
50
+ base_url="https://internal_api.example.com",
51
+ token="SuperSecretToken",
52
+ verify_ssl="/path/to/certificate_bundle.pem",
53
+ )
54
+ ```
55
+
56
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
57
+
58
+ ```python
59
+ client = AuthenticatedClient(
60
+ base_url="https://internal_api.example.com",
61
+ token="SuperSecretToken",
62
+ verify_ssl=False
63
+ )
64
+ ```
65
+
66
+ Things to know:
67
+ 1. Every path/method combo becomes a Python module with four functions:
68
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
69
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
70
+ 1. `asyncio`: Like `sync` but async instead of blocking
71
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
72
+
73
+ 1. All path/query params, and bodies become method arguments.
74
+ 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
75
+ 1. Any endpoint which did not have a tag will be in `ab_client_token_validator.api.default`
76
+
77
+ ## Advanced customizations
78
+
79
+ There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
80
+
81
+ ```python
82
+ from ab_client_token_validator import Client
83
+
84
+ def log_request(request):
85
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
86
+
87
+ def log_response(response):
88
+ request = response.request
89
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
90
+
91
+ client = Client(
92
+ base_url="https://api.example.com",
93
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
94
+ )
95
+
96
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
97
+ ```
98
+
99
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
100
+
101
+ ```python
102
+ import httpx
103
+ from ab_client_token_validator import Client
104
+
105
+ client = Client(
106
+ base_url="https://api.example.com",
107
+ )
108
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
109
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
110
+ ```
111
+
112
+ ## Building / publishing this package
113
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
114
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
115
+ 1. If you're using a private repository, configure it with Poetry
116
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
117
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
118
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
119
+
120
+ If you want to install this client into another project without publishing it (e.g. for development) then:
121
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
122
+ 1. If that project is not using Poetry:
123
+ 1. Build a wheel with `poetry build -f wheel`
124
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
@@ -0,0 +1,8 @@
1
+ """A client library for accessing FastAPI"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,172 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.http_validation_error import HTTPValidationError
9
+ from ...models.validate_token_request import ValidateTokenRequest
10
+ from ...models.validated_oidc_claims import ValidatedOIDCClaims
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: ValidateTokenRequest,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/validate",
23
+ }
24
+
25
+ _kwargs["json"] = body.to_dict()
26
+
27
+ headers["Content-Type"] = "application/json"
28
+
29
+ _kwargs["headers"] = headers
30
+ return _kwargs
31
+
32
+
33
+ def _parse_response(
34
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
35
+ ) -> Optional[Union[HTTPValidationError, ValidatedOIDCClaims]]:
36
+ if response.status_code == 200:
37
+ response_200 = ValidatedOIDCClaims.from_dict(response.json())
38
+
39
+ return response_200
40
+ if response.status_code == 422:
41
+ response_422 = HTTPValidationError.from_dict(response.json())
42
+
43
+ return response_422
44
+ if client.raise_on_unexpected_status:
45
+ raise errors.UnexpectedStatus(response.status_code, response.content)
46
+ else:
47
+ return None
48
+
49
+
50
+ def _build_response(
51
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
52
+ ) -> Response[Union[HTTPValidationError, ValidatedOIDCClaims]]:
53
+ return Response(
54
+ status_code=HTTPStatus(response.status_code),
55
+ content=response.content,
56
+ headers=response.headers,
57
+ parsed=_parse_response(client=client, response=response),
58
+ )
59
+
60
+
61
+ def sync_detailed(
62
+ *,
63
+ client: Union[AuthenticatedClient, Client],
64
+ body: ValidateTokenRequest,
65
+ ) -> Response[Union[HTTPValidationError, ValidatedOIDCClaims]]:
66
+ """Validate Token
67
+
68
+ Validate a token.
69
+
70
+ Args:
71
+ body (ValidateTokenRequest): Schema for token request.
72
+
73
+ Raises:
74
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
75
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
76
+
77
+ Returns:
78
+ Response[Union[HTTPValidationError, ValidatedOIDCClaims]]
79
+ """
80
+
81
+ kwargs = _get_kwargs(
82
+ body=body,
83
+ )
84
+
85
+ response = client.get_httpx_client().request(
86
+ **kwargs,
87
+ )
88
+
89
+ return _build_response(client=client, response=response)
90
+
91
+
92
+ def sync(
93
+ *,
94
+ client: Union[AuthenticatedClient, Client],
95
+ body: ValidateTokenRequest,
96
+ ) -> Optional[Union[HTTPValidationError, ValidatedOIDCClaims]]:
97
+ """Validate Token
98
+
99
+ Validate a token.
100
+
101
+ Args:
102
+ body (ValidateTokenRequest): Schema for token request.
103
+
104
+ Raises:
105
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
106
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
107
+
108
+ Returns:
109
+ Union[HTTPValidationError, ValidatedOIDCClaims]
110
+ """
111
+
112
+ return sync_detailed(
113
+ client=client,
114
+ body=body,
115
+ ).parsed
116
+
117
+
118
+ async def asyncio_detailed(
119
+ *,
120
+ client: Union[AuthenticatedClient, Client],
121
+ body: ValidateTokenRequest,
122
+ ) -> Response[Union[HTTPValidationError, ValidatedOIDCClaims]]:
123
+ """Validate Token
124
+
125
+ Validate a token.
126
+
127
+ Args:
128
+ body (ValidateTokenRequest): Schema for token request.
129
+
130
+ Raises:
131
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
132
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
133
+
134
+ Returns:
135
+ Response[Union[HTTPValidationError, ValidatedOIDCClaims]]
136
+ """
137
+
138
+ kwargs = _get_kwargs(
139
+ body=body,
140
+ )
141
+
142
+ response = await client.get_async_httpx_client().request(**kwargs)
143
+
144
+ return _build_response(client=client, response=response)
145
+
146
+
147
+ async def asyncio(
148
+ *,
149
+ client: Union[AuthenticatedClient, Client],
150
+ body: ValidateTokenRequest,
151
+ ) -> Optional[Union[HTTPValidationError, ValidatedOIDCClaims]]:
152
+ """Validate Token
153
+
154
+ Validate a token.
155
+
156
+ Args:
157
+ body (ValidateTokenRequest): Schema for token request.
158
+
159
+ Raises:
160
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
161
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
162
+
163
+ Returns:
164
+ Union[HTTPValidationError, ValidatedOIDCClaims]
165
+ """
166
+
167
+ return (
168
+ await asyncio_detailed(
169
+ client=client,
170
+ body=body,
171
+ )
172
+ ).parsed
@@ -0,0 +1,268 @@
1
+ import ssl
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+ from attrs import define, evolve, field
6
+
7
+
8
+ @define
9
+ class Client:
10
+ """A class for keeping track of data related to the API
11
+
12
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
13
+
14
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
15
+
16
+ ``cookies``: A dictionary of cookies to be sent with every request
17
+
18
+ ``headers``: A dictionary of headers to be sent with every request
19
+
20
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
21
+ httpx.TimeoutException if this is exceeded.
22
+
23
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
24
+ but can be set to False for testing purposes.
25
+
26
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
27
+
28
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
29
+
30
+
31
+ Attributes:
32
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
33
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
34
+ argument to the constructor.
35
+ """
36
+
37
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
38
+ _base_url: str = field(alias="base_url")
39
+ _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
40
+ _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
41
+ _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
42
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
43
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
44
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
45
+ _client: Optional[httpx.Client] = field(default=None, init=False)
46
+ _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
47
+
48
+ def with_headers(self, headers: dict[str, str]) -> "Client":
49
+ """Get a new client matching this one with additional headers"""
50
+ if self._client is not None:
51
+ self._client.headers.update(headers)
52
+ if self._async_client is not None:
53
+ self._async_client.headers.update(headers)
54
+ return evolve(self, headers={**self._headers, **headers})
55
+
56
+ def with_cookies(self, cookies: dict[str, str]) -> "Client":
57
+ """Get a new client matching this one with additional cookies"""
58
+ if self._client is not None:
59
+ self._client.cookies.update(cookies)
60
+ if self._async_client is not None:
61
+ self._async_client.cookies.update(cookies)
62
+ return evolve(self, cookies={**self._cookies, **cookies})
63
+
64
+ def with_timeout(self, timeout: httpx.Timeout) -> "Client":
65
+ """Get a new client matching this one with a new timeout (in seconds)"""
66
+ if self._client is not None:
67
+ self._client.timeout = timeout
68
+ if self._async_client is not None:
69
+ self._async_client.timeout = timeout
70
+ return evolve(self, timeout=timeout)
71
+
72
+ def set_httpx_client(self, client: httpx.Client) -> "Client":
73
+ """Manually set the underlying httpx.Client
74
+
75
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
76
+ """
77
+ self._client = client
78
+ return self
79
+
80
+ def get_httpx_client(self) -> httpx.Client:
81
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
82
+ if self._client is None:
83
+ self._client = httpx.Client(
84
+ base_url=self._base_url,
85
+ cookies=self._cookies,
86
+ headers=self._headers,
87
+ timeout=self._timeout,
88
+ verify=self._verify_ssl,
89
+ follow_redirects=self._follow_redirects,
90
+ **self._httpx_args,
91
+ )
92
+ return self._client
93
+
94
+ def __enter__(self) -> "Client":
95
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
96
+ self.get_httpx_client().__enter__()
97
+ return self
98
+
99
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
100
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
101
+ self.get_httpx_client().__exit__(*args, **kwargs)
102
+
103
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
104
+ """Manually the underlying httpx.AsyncClient
105
+
106
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
107
+ """
108
+ self._async_client = async_client
109
+ return self
110
+
111
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
112
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
113
+ if self._async_client is None:
114
+ self._async_client = httpx.AsyncClient(
115
+ base_url=self._base_url,
116
+ cookies=self._cookies,
117
+ headers=self._headers,
118
+ timeout=self._timeout,
119
+ verify=self._verify_ssl,
120
+ follow_redirects=self._follow_redirects,
121
+ **self._httpx_args,
122
+ )
123
+ return self._async_client
124
+
125
+ async def __aenter__(self) -> "Client":
126
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
127
+ await self.get_async_httpx_client().__aenter__()
128
+ return self
129
+
130
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
131
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
132
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
133
+
134
+
135
+ @define
136
+ class AuthenticatedClient:
137
+ """A Client which has been authenticated for use on secured endpoints
138
+
139
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
140
+
141
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
142
+
143
+ ``cookies``: A dictionary of cookies to be sent with every request
144
+
145
+ ``headers``: A dictionary of headers to be sent with every request
146
+
147
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
148
+ httpx.TimeoutException if this is exceeded.
149
+
150
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
151
+ but can be set to False for testing purposes.
152
+
153
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
154
+
155
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
156
+
157
+
158
+ Attributes:
159
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
160
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
161
+ argument to the constructor.
162
+ token: The token to use for authentication
163
+ prefix: The prefix to use for the Authorization header
164
+ auth_header_name: The name of the Authorization header
165
+ """
166
+
167
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
168
+ _base_url: str = field(alias="base_url")
169
+ _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
170
+ _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
171
+ _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
172
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
173
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
174
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
175
+ _client: Optional[httpx.Client] = field(default=None, init=False)
176
+ _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
177
+
178
+ token: str
179
+ prefix: str = "Bearer"
180
+ auth_header_name: str = "Authorization"
181
+
182
+ def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
183
+ """Get a new client matching this one with additional headers"""
184
+ if self._client is not None:
185
+ self._client.headers.update(headers)
186
+ if self._async_client is not None:
187
+ self._async_client.headers.update(headers)
188
+ return evolve(self, headers={**self._headers, **headers})
189
+
190
+ def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
191
+ """Get a new client matching this one with additional cookies"""
192
+ if self._client is not None:
193
+ self._client.cookies.update(cookies)
194
+ if self._async_client is not None:
195
+ self._async_client.cookies.update(cookies)
196
+ return evolve(self, cookies={**self._cookies, **cookies})
197
+
198
+ def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
199
+ """Get a new client matching this one with a new timeout (in seconds)"""
200
+ if self._client is not None:
201
+ self._client.timeout = timeout
202
+ if self._async_client is not None:
203
+ self._async_client.timeout = timeout
204
+ return evolve(self, timeout=timeout)
205
+
206
+ def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
207
+ """Manually set the underlying httpx.Client
208
+
209
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
210
+ """
211
+ self._client = client
212
+ return self
213
+
214
+ def get_httpx_client(self) -> httpx.Client:
215
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
216
+ if self._client is None:
217
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
218
+ self._client = httpx.Client(
219
+ base_url=self._base_url,
220
+ cookies=self._cookies,
221
+ headers=self._headers,
222
+ timeout=self._timeout,
223
+ verify=self._verify_ssl,
224
+ follow_redirects=self._follow_redirects,
225
+ **self._httpx_args,
226
+ )
227
+ return self._client
228
+
229
+ def __enter__(self) -> "AuthenticatedClient":
230
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
231
+ self.get_httpx_client().__enter__()
232
+ return self
233
+
234
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
235
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
236
+ self.get_httpx_client().__exit__(*args, **kwargs)
237
+
238
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
239
+ """Manually the underlying httpx.AsyncClient
240
+
241
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
242
+ """
243
+ self._async_client = async_client
244
+ return self
245
+
246
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
247
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
248
+ if self._async_client is None:
249
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
250
+ self._async_client = httpx.AsyncClient(
251
+ base_url=self._base_url,
252
+ cookies=self._cookies,
253
+ headers=self._headers,
254
+ timeout=self._timeout,
255
+ verify=self._verify_ssl,
256
+ follow_redirects=self._follow_redirects,
257
+ **self._httpx_args,
258
+ )
259
+ return self._async_client
260
+
261
+ async def __aenter__(self) -> "AuthenticatedClient":
262
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
263
+ await self.get_async_httpx_client().__aenter__()
264
+ return self
265
+
266
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
267
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
268
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
@@ -0,0 +1,16 @@
1
+ """Contains shared errors types that can be raised from API functions"""
2
+
3
+
4
+ class UnexpectedStatus(Exception):
5
+ """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
6
+
7
+ def __init__(self, status_code: int, content: bytes):
8
+ self.status_code = status_code
9
+ self.content = content
10
+
11
+ super().__init__(
12
+ f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
13
+ )
14
+
15
+
16
+ __all__ = ["UnexpectedStatus"]
@@ -0,0 +1,13 @@
1
+ """Contains all the data models used in inputs/outputs"""
2
+
3
+ from .http_validation_error import HTTPValidationError
4
+ from .validate_token_request import ValidateTokenRequest
5
+ from .validated_oidc_claims import ValidatedOIDCClaims
6
+ from .validation_error import ValidationError
7
+
8
+ __all__ = (
9
+ "HTTPValidationError",
10
+ "ValidatedOIDCClaims",
11
+ "ValidateTokenRequest",
12
+ "ValidationError",
13
+ )
@@ -0,0 +1,75 @@
1
+ from collections.abc import Mapping
2
+ from typing import TYPE_CHECKING, Any, TypeVar, Union
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ from ..types import UNSET, Unset
8
+
9
+ if TYPE_CHECKING:
10
+ from ..models.validation_error import ValidationError
11
+
12
+
13
+ T = TypeVar("T", bound="HTTPValidationError")
14
+
15
+
16
+ @_attrs_define
17
+ class HTTPValidationError:
18
+ """
19
+ Attributes:
20
+ detail (Union[Unset, list['ValidationError']]):
21
+ """
22
+
23
+ detail: Union[Unset, list["ValidationError"]] = UNSET
24
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
25
+
26
+ def to_dict(self) -> dict[str, Any]:
27
+ detail: Union[Unset, list[dict[str, Any]]] = UNSET
28
+ if not isinstance(self.detail, Unset):
29
+ detail = []
30
+ for detail_item_data in self.detail:
31
+ detail_item = detail_item_data.to_dict()
32
+ detail.append(detail_item)
33
+
34
+ field_dict: dict[str, Any] = {}
35
+ field_dict.update(self.additional_properties)
36
+ field_dict.update({})
37
+ if detail is not UNSET:
38
+ field_dict["detail"] = detail
39
+
40
+ return field_dict
41
+
42
+ @classmethod
43
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
44
+ from ..models.validation_error import ValidationError
45
+
46
+ d = dict(src_dict)
47
+ detail = []
48
+ _detail = d.pop("detail", UNSET)
49
+ for detail_item_data in _detail or []:
50
+ detail_item = ValidationError.from_dict(detail_item_data)
51
+
52
+ detail.append(detail_item)
53
+
54
+ http_validation_error = cls(
55
+ detail=detail,
56
+ )
57
+
58
+ http_validation_error.additional_properties = d
59
+ return http_validation_error
60
+
61
+ @property
62
+ def additional_keys(self) -> list[str]:
63
+ return list(self.additional_properties.keys())
64
+
65
+ def __getitem__(self, key: str) -> Any:
66
+ return self.additional_properties[key]
67
+
68
+ def __setitem__(self, key: str, value: Any) -> None:
69
+ self.additional_properties[key] = value
70
+
71
+ def __delitem__(self, key: str) -> None:
72
+ del self.additional_properties[key]
73
+
74
+ def __contains__(self, key: str) -> bool:
75
+ return key in self.additional_properties
@@ -0,0 +1,60 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="ValidateTokenRequest")
8
+
9
+
10
+ @_attrs_define
11
+ class ValidateTokenRequest:
12
+ """Schema for token request.
13
+
14
+ Attributes:
15
+ token (str):
16
+ """
17
+
18
+ token: str
19
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
20
+
21
+ def to_dict(self) -> dict[str, Any]:
22
+ token = self.token
23
+
24
+ field_dict: dict[str, Any] = {}
25
+ field_dict.update(self.additional_properties)
26
+ field_dict.update(
27
+ {
28
+ "token": token,
29
+ }
30
+ )
31
+
32
+ return field_dict
33
+
34
+ @classmethod
35
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
36
+ d = dict(src_dict)
37
+ token = d.pop("token")
38
+
39
+ validate_token_request = cls(
40
+ token=token,
41
+ )
42
+
43
+ validate_token_request.additional_properties = d
44
+ return validate_token_request
45
+
46
+ @property
47
+ def additional_keys(self) -> list[str]:
48
+ return list(self.additional_properties.keys())
49
+
50
+ def __getitem__(self, key: str) -> Any:
51
+ return self.additional_properties[key]
52
+
53
+ def __setitem__(self, key: str, value: Any) -> None:
54
+ self.additional_properties[key] = value
55
+
56
+ def __delitem__(self, key: str) -> None:
57
+ del self.additional_properties[key]
58
+
59
+ def __contains__(self, key: str) -> bool:
60
+ return key in self.additional_properties
@@ -0,0 +1,276 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar, Union, cast
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ from ..types import UNSET, Unset
8
+
9
+ T = TypeVar("T", bound="ValidatedOIDCClaims")
10
+
11
+
12
+ @_attrs_define
13
+ class ValidatedOIDCClaims:
14
+ """
15
+ Attributes:
16
+ iss (str):
17
+ sub (str):
18
+ aud (Union[list[str], str]):
19
+ exp (int):
20
+ iat (int):
21
+ auth_time (int):
22
+ acr (str):
23
+ email (Union[None, Unset, str]):
24
+ email_verified (Union[None, Unset, bool]):
25
+ name (Union[None, Unset, str]):
26
+ given_name (Union[None, Unset, str]):
27
+ preferred_username (Union[None, Unset, str]):
28
+ nickname (Union[None, Unset, str]):
29
+ groups (Union[None, Unset, list[str]]):
30
+ """
31
+
32
+ iss: str
33
+ sub: str
34
+ aud: Union[list[str], str]
35
+ exp: int
36
+ iat: int
37
+ auth_time: int
38
+ acr: str
39
+ email: Union[None, Unset, str] = UNSET
40
+ email_verified: Union[None, Unset, bool] = UNSET
41
+ name: Union[None, Unset, str] = UNSET
42
+ given_name: Union[None, Unset, str] = UNSET
43
+ preferred_username: Union[None, Unset, str] = UNSET
44
+ nickname: Union[None, Unset, str] = UNSET
45
+ groups: Union[None, Unset, list[str]] = UNSET
46
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
47
+
48
+ def to_dict(self) -> dict[str, Any]:
49
+ iss = self.iss
50
+
51
+ sub = self.sub
52
+
53
+ aud: Union[list[str], str]
54
+ if isinstance(self.aud, list):
55
+ aud = self.aud
56
+
57
+ else:
58
+ aud = self.aud
59
+
60
+ exp = self.exp
61
+
62
+ iat = self.iat
63
+
64
+ auth_time = self.auth_time
65
+
66
+ acr = self.acr
67
+
68
+ email: Union[None, Unset, str]
69
+ if isinstance(self.email, Unset):
70
+ email = UNSET
71
+ else:
72
+ email = self.email
73
+
74
+ email_verified: Union[None, Unset, bool]
75
+ if isinstance(self.email_verified, Unset):
76
+ email_verified = UNSET
77
+ else:
78
+ email_verified = self.email_verified
79
+
80
+ name: Union[None, Unset, str]
81
+ if isinstance(self.name, Unset):
82
+ name = UNSET
83
+ else:
84
+ name = self.name
85
+
86
+ given_name: Union[None, Unset, str]
87
+ if isinstance(self.given_name, Unset):
88
+ given_name = UNSET
89
+ else:
90
+ given_name = self.given_name
91
+
92
+ preferred_username: Union[None, Unset, str]
93
+ if isinstance(self.preferred_username, Unset):
94
+ preferred_username = UNSET
95
+ else:
96
+ preferred_username = self.preferred_username
97
+
98
+ nickname: Union[None, Unset, str]
99
+ if isinstance(self.nickname, Unset):
100
+ nickname = UNSET
101
+ else:
102
+ nickname = self.nickname
103
+
104
+ groups: Union[None, Unset, list[str]]
105
+ if isinstance(self.groups, Unset):
106
+ groups = UNSET
107
+ elif isinstance(self.groups, list):
108
+ groups = self.groups
109
+
110
+ else:
111
+ groups = self.groups
112
+
113
+ field_dict: dict[str, Any] = {}
114
+ field_dict.update(self.additional_properties)
115
+ field_dict.update(
116
+ {
117
+ "iss": iss,
118
+ "sub": sub,
119
+ "aud": aud,
120
+ "exp": exp,
121
+ "iat": iat,
122
+ "auth_time": auth_time,
123
+ "acr": acr,
124
+ }
125
+ )
126
+ if email is not UNSET:
127
+ field_dict["email"] = email
128
+ if email_verified is not UNSET:
129
+ field_dict["email_verified"] = email_verified
130
+ if name is not UNSET:
131
+ field_dict["name"] = name
132
+ if given_name is not UNSET:
133
+ field_dict["given_name"] = given_name
134
+ if preferred_username is not UNSET:
135
+ field_dict["preferred_username"] = preferred_username
136
+ if nickname is not UNSET:
137
+ field_dict["nickname"] = nickname
138
+ if groups is not UNSET:
139
+ field_dict["groups"] = groups
140
+
141
+ return field_dict
142
+
143
+ @classmethod
144
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
145
+ d = dict(src_dict)
146
+ iss = d.pop("iss")
147
+
148
+ sub = d.pop("sub")
149
+
150
+ def _parse_aud(data: object) -> Union[list[str], str]:
151
+ try:
152
+ if not isinstance(data, list):
153
+ raise TypeError()
154
+ aud_type_1 = cast(list[str], data)
155
+
156
+ return aud_type_1
157
+ except: # noqa: E722
158
+ pass
159
+ return cast(Union[list[str], str], data)
160
+
161
+ aud = _parse_aud(d.pop("aud"))
162
+
163
+ exp = d.pop("exp")
164
+
165
+ iat = d.pop("iat")
166
+
167
+ auth_time = d.pop("auth_time")
168
+
169
+ acr = d.pop("acr")
170
+
171
+ def _parse_email(data: object) -> Union[None, Unset, str]:
172
+ if data is None:
173
+ return data
174
+ if isinstance(data, Unset):
175
+ return data
176
+ return cast(Union[None, Unset, str], data)
177
+
178
+ email = _parse_email(d.pop("email", UNSET))
179
+
180
+ def _parse_email_verified(data: object) -> Union[None, Unset, bool]:
181
+ if data is None:
182
+ return data
183
+ if isinstance(data, Unset):
184
+ return data
185
+ return cast(Union[None, Unset, bool], data)
186
+
187
+ email_verified = _parse_email_verified(d.pop("email_verified", UNSET))
188
+
189
+ def _parse_name(data: object) -> Union[None, Unset, str]:
190
+ if data is None:
191
+ return data
192
+ if isinstance(data, Unset):
193
+ return data
194
+ return cast(Union[None, Unset, str], data)
195
+
196
+ name = _parse_name(d.pop("name", UNSET))
197
+
198
+ def _parse_given_name(data: object) -> Union[None, Unset, str]:
199
+ if data is None:
200
+ return data
201
+ if isinstance(data, Unset):
202
+ return data
203
+ return cast(Union[None, Unset, str], data)
204
+
205
+ given_name = _parse_given_name(d.pop("given_name", UNSET))
206
+
207
+ def _parse_preferred_username(data: object) -> Union[None, Unset, str]:
208
+ if data is None:
209
+ return data
210
+ if isinstance(data, Unset):
211
+ return data
212
+ return cast(Union[None, Unset, str], data)
213
+
214
+ preferred_username = _parse_preferred_username(d.pop("preferred_username", UNSET))
215
+
216
+ def _parse_nickname(data: object) -> Union[None, Unset, str]:
217
+ if data is None:
218
+ return data
219
+ if isinstance(data, Unset):
220
+ return data
221
+ return cast(Union[None, Unset, str], data)
222
+
223
+ nickname = _parse_nickname(d.pop("nickname", UNSET))
224
+
225
+ def _parse_groups(data: object) -> Union[None, Unset, list[str]]:
226
+ if data is None:
227
+ return data
228
+ if isinstance(data, Unset):
229
+ return data
230
+ try:
231
+ if not isinstance(data, list):
232
+ raise TypeError()
233
+ groups_type_0 = cast(list[str], data)
234
+
235
+ return groups_type_0
236
+ except: # noqa: E722
237
+ pass
238
+ return cast(Union[None, Unset, list[str]], data)
239
+
240
+ groups = _parse_groups(d.pop("groups", UNSET))
241
+
242
+ validated_oidc_claims = cls(
243
+ iss=iss,
244
+ sub=sub,
245
+ aud=aud,
246
+ exp=exp,
247
+ iat=iat,
248
+ auth_time=auth_time,
249
+ acr=acr,
250
+ email=email,
251
+ email_verified=email_verified,
252
+ name=name,
253
+ given_name=given_name,
254
+ preferred_username=preferred_username,
255
+ nickname=nickname,
256
+ groups=groups,
257
+ )
258
+
259
+ validated_oidc_claims.additional_properties = d
260
+ return validated_oidc_claims
261
+
262
+ @property
263
+ def additional_keys(self) -> list[str]:
264
+ return list(self.additional_properties.keys())
265
+
266
+ def __getitem__(self, key: str) -> Any:
267
+ return self.additional_properties[key]
268
+
269
+ def __setitem__(self, key: str, value: Any) -> None:
270
+ self.additional_properties[key] = value
271
+
272
+ def __delitem__(self, key: str) -> None:
273
+ del self.additional_properties[key]
274
+
275
+ def __contains__(self, key: str) -> bool:
276
+ return key in self.additional_properties
@@ -0,0 +1,88 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar, Union, cast
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="ValidationError")
8
+
9
+
10
+ @_attrs_define
11
+ class ValidationError:
12
+ """
13
+ Attributes:
14
+ loc (list[Union[int, str]]):
15
+ msg (str):
16
+ type_ (str):
17
+ """
18
+
19
+ loc: list[Union[int, str]]
20
+ msg: str
21
+ type_: str
22
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
23
+
24
+ def to_dict(self) -> dict[str, Any]:
25
+ loc = []
26
+ for loc_item_data in self.loc:
27
+ loc_item: Union[int, str]
28
+ loc_item = loc_item_data
29
+ loc.append(loc_item)
30
+
31
+ msg = self.msg
32
+
33
+ type_ = self.type_
34
+
35
+ field_dict: dict[str, Any] = {}
36
+ field_dict.update(self.additional_properties)
37
+ field_dict.update(
38
+ {
39
+ "loc": loc,
40
+ "msg": msg,
41
+ "type": type_,
42
+ }
43
+ )
44
+
45
+ return field_dict
46
+
47
+ @classmethod
48
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
49
+ d = dict(src_dict)
50
+ loc = []
51
+ _loc = d.pop("loc")
52
+ for loc_item_data in _loc:
53
+
54
+ def _parse_loc_item(data: object) -> Union[int, str]:
55
+ return cast(Union[int, str], data)
56
+
57
+ loc_item = _parse_loc_item(loc_item_data)
58
+
59
+ loc.append(loc_item)
60
+
61
+ msg = d.pop("msg")
62
+
63
+ type_ = d.pop("type")
64
+
65
+ validation_error = cls(
66
+ loc=loc,
67
+ msg=msg,
68
+ type_=type_,
69
+ )
70
+
71
+ validation_error.additional_properties = d
72
+ return validation_error
73
+
74
+ @property
75
+ def additional_keys(self) -> list[str]:
76
+ return list(self.additional_properties.keys())
77
+
78
+ def __getitem__(self, key: str) -> Any:
79
+ return self.additional_properties[key]
80
+
81
+ def __setitem__(self, key: str, value: Any) -> None:
82
+ self.additional_properties[key] = value
83
+
84
+ def __delitem__(self, key: str) -> None:
85
+ del self.additional_properties[key]
86
+
87
+ def __contains__(self, key: str) -> bool:
88
+ return key in self.additional_properties
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561
@@ -0,0 +1,54 @@
1
+ """Contains some shared types for properties"""
2
+
3
+ from collections.abc import Mapping, MutableMapping
4
+ from http import HTTPStatus
5
+ from typing import IO, BinaryIO, Generic, Literal, Optional, TypeVar, Union
6
+
7
+ from attrs import define
8
+
9
+
10
+ class Unset:
11
+ def __bool__(self) -> Literal[False]:
12
+ return False
13
+
14
+
15
+ UNSET: Unset = Unset()
16
+
17
+ # The types that `httpx.Client(files=)` can accept, copied from that library.
18
+ FileContent = Union[IO[bytes], bytes, str]
19
+ FileTypes = Union[
20
+ # (filename, file (or bytes), content_type)
21
+ tuple[Optional[str], FileContent, Optional[str]],
22
+ # (filename, file (or bytes), content_type, headers)
23
+ tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]],
24
+ ]
25
+ RequestFiles = list[tuple[str, FileTypes]]
26
+
27
+
28
+ @define
29
+ class File:
30
+ """Contains information for file uploads"""
31
+
32
+ payload: BinaryIO
33
+ file_name: Optional[str] = None
34
+ mime_type: Optional[str] = None
35
+
36
+ def to_tuple(self) -> FileTypes:
37
+ """Return a tuple representation that httpx will accept for multipart/form-data"""
38
+ return self.file_name, self.payload, self.mime_type
39
+
40
+
41
+ T = TypeVar("T")
42
+
43
+
44
+ @define
45
+ class Response(Generic[T]):
46
+ """A response from an endpoint"""
47
+
48
+ status_code: HTTPStatus
49
+ content: bytes
50
+ headers: MutableMapping[str, str]
51
+ parsed: Optional[T]
52
+
53
+
54
+ __all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"]
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "ab-client-token-validator"
3
+ version = "0.1.0"
4
+ description = "A client library for accessing FastAPI"
5
+ authors = []
6
+ requires-python = "~=3.9"
7
+ readme = "README.md"
8
+ dependencies = [
9
+ "httpx>=0.23.0,<0.29.0",
10
+ "attrs>=22.2.0",
11
+ "python-dateutil>=2.8.0,<3",
12
+ ]
13
+
14
+ [tool.hatch.build.targets.sdist]
15
+ include = [
16
+ "ab_client_token_validator",
17
+ "CHANGELOG.md",
18
+ "ab_client_token_validator/py.typed",
19
+ ]
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ include = [
23
+ "ab_client_token_validator",
24
+ "CHANGELOG.md",
25
+ "ab_client_token_validator/py.typed",
26
+ ]
27
+
28
+ [build-system]
29
+ requires = ["hatchling"]
30
+ build-backend = "hatchling.build"
31
+
32
+ [tool.ruff]
33
+ line-length = 120
34
+
35
+ [tool.ruff.lint]
36
+ select = ["F", "I", "UP"]