tweetapi-sdk 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.
Files changed (58) hide show
  1. tweetapi_sdk-0.1.0/PKG-INFO +138 -0
  2. tweetapi_sdk-0.1.0/README.md +123 -0
  3. tweetapi_sdk-0.1.0/pyproject.toml +25 -0
  4. tweetapi_sdk-0.1.0/tweetapi_sdk/__init__.py +8 -0
  5. tweetapi_sdk-0.1.0/tweetapi_sdk/api/__init__.py +1 -0
  6. tweetapi_sdk-0.1.0/tweetapi_sdk/api/account/__init__.py +1 -0
  7. tweetapi_sdk-0.1.0/tweetapi_sdk/api/account/get_me.py +134 -0
  8. tweetapi_sdk-0.1.0/tweetapi_sdk/api/billing/__init__.py +1 -0
  9. tweetapi_sdk-0.1.0/tweetapi_sdk/api/billing/create_checkout.py +187 -0
  10. tweetapi_sdk-0.1.0/tweetapi_sdk/api/billing/list_packs.py +126 -0
  11. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/__init__.py +1 -0
  12. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_likers.py +230 -0
  13. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_quotes.py +226 -0
  14. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_replies.py +215 -0
  15. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_retweeters.py +230 -0
  16. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_thread.py +211 -0
  17. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_tweet.py +198 -0
  18. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/get_tweets.py +208 -0
  19. tweetapi_sdk-0.1.0/tweetapi_sdk/api/tweets/search_tweets.py +267 -0
  20. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/__init__.py +1 -0
  21. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/get_followers.py +239 -0
  22. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/get_following.py +231 -0
  23. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/get_user.py +198 -0
  24. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/get_user_tweets.py +226 -0
  25. tweetapi_sdk-0.1.0/tweetapi_sdk/api/users/get_users.py +216 -0
  26. tweetapi_sdk-0.1.0/tweetapi_sdk/client.py +268 -0
  27. tweetapi_sdk-0.1.0/tweetapi_sdk/errors.py +16 -0
  28. tweetapi_sdk-0.1.0/tweetapi_sdk/models/__init__.py +61 -0
  29. tweetapi_sdk-0.1.0/tweetapi_sdk/models/batch_error.py +79 -0
  30. tweetapi_sdk-0.1.0/tweetapi_sdk/models/batch_error_code.py +15 -0
  31. tweetapi_sdk-0.1.0/tweetapi_sdk/models/batch_meta.py +126 -0
  32. tweetapi_sdk-0.1.0/tweetapi_sdk/models/batch_meta_cache.py +11 -0
  33. tweetapi_sdk-0.1.0/tweetapi_sdk/models/create_checkout_body.py +63 -0
  34. tweetapi_sdk-0.1.0/tweetapi_sdk/models/create_checkout_body_pack.py +11 -0
  35. tweetapi_sdk-0.1.0/tweetapi_sdk/models/create_checkout_response_200.py +97 -0
  36. tweetapi_sdk-0.1.0/tweetapi_sdk/models/error.py +75 -0
  37. tweetapi_sdk-0.1.0/tweetapi_sdk/models/error_error.py +71 -0
  38. tweetapi_sdk-0.1.0/tweetapi_sdk/models/error_error_code.py +22 -0
  39. tweetapi_sdk-0.1.0/tweetapi_sdk/models/get_me_response_200.py +88 -0
  40. tweetapi_sdk-0.1.0/tweetapi_sdk/models/get_tweets_body.py +61 -0
  41. tweetapi_sdk-0.1.0/tweetapi_sdk/models/get_users_body.py +61 -0
  42. tweetapi_sdk-0.1.0/tweetapi_sdk/models/list_packs_response_200.py +79 -0
  43. tweetapi_sdk-0.1.0/tweetapi_sdk/models/list_packs_response_200_data_item.py +97 -0
  44. tweetapi_sdk-0.1.0/tweetapi_sdk/models/media.py +96 -0
  45. tweetapi_sdk-0.1.0/tweetapi_sdk/models/media_type.py +10 -0
  46. tweetapi_sdk-0.1.0/tweetapi_sdk/models/meta.py +106 -0
  47. tweetapi_sdk-0.1.0/tweetapi_sdk/models/meta_cache.py +10 -0
  48. tweetapi_sdk-0.1.0/tweetapi_sdk/models/search_tweets_product.py +12 -0
  49. tweetapi_sdk-0.1.0/tweetapi_sdk/models/tweet.py +310 -0
  50. tweetapi_sdk-0.1.0/tweetapi_sdk/models/tweet_batch.py +150 -0
  51. tweetapi_sdk-0.1.0/tweetapi_sdk/models/tweet_page.py +133 -0
  52. tweetapi_sdk-0.1.0/tweetapi_sdk/models/tweet_response.py +128 -0
  53. tweetapi_sdk-0.1.0/tweetapi_sdk/models/user.py +204 -0
  54. tweetapi_sdk-0.1.0/tweetapi_sdk/models/user_batch.py +150 -0
  55. tweetapi_sdk-0.1.0/tweetapi_sdk/models/user_page.py +133 -0
  56. tweetapi_sdk-0.1.0/tweetapi_sdk/models/user_response.py +128 -0
  57. tweetapi_sdk-0.1.0/tweetapi_sdk/py.typed +1 -0
  58. tweetapi_sdk-0.1.0/tweetapi_sdk/types.py +54 -0
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: tweetapi-sdk
3
+ Version: 0.1.0
4
+ Summary: A client library for accessing tweetapi.dev API
5
+ Requires-Python: >=3.11,<4.0
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.11
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Classifier: Programming Language :: Python :: 3.14
11
+ Requires-Dist: attrs (>=22.2.0)
12
+ Requires-Dist: httpx (>=0.23.1,<0.29.0)
13
+ Description-Content-Type: text/markdown
14
+
15
+ # tweetapi-sdk
16
+ A client library for accessing tweetapi.dev API
17
+
18
+ ## Usage
19
+ First, create a client:
20
+
21
+ ```python
22
+ from tweetapi_sdk import Client
23
+
24
+ client = Client(base_url="https://api.example.com")
25
+ ```
26
+
27
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
28
+
29
+ ```python
30
+ from tweetapi_sdk import AuthenticatedClient
31
+
32
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
33
+ ```
34
+
35
+ Now call your endpoint and use your models:
36
+
37
+ ```python
38
+ from tweetapi_sdk.models import MyDataModel
39
+ from tweetapi_sdk.api.my_tag import get_my_data_model
40
+ from tweetapi_sdk.types import Response
41
+
42
+ with client as client:
43
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
44
+ # or if you need more info (e.g. status_code)
45
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
46
+ ```
47
+
48
+ Or do the same thing with an async version:
49
+
50
+ ```python
51
+ from tweetapi_sdk.models import MyDataModel
52
+ from tweetapi_sdk.api.my_tag import get_my_data_model
53
+ from tweetapi_sdk.types import Response
54
+
55
+ async with client as client:
56
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
57
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
58
+ ```
59
+
60
+ 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.
61
+
62
+ ```python
63
+ client = AuthenticatedClient(
64
+ base_url="https://internal_api.example.com",
65
+ token="SuperSecretToken",
66
+ verify_ssl="/path/to/certificate_bundle.pem",
67
+ )
68
+ ```
69
+
70
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
71
+
72
+ ```python
73
+ client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
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 `tweetapi_sdk.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 tweetapi_sdk import Client
93
+
94
+
95
+ def log_request(request):
96
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
97
+
98
+
99
+ def log_response(response):
100
+ request = response.request
101
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
102
+
103
+
104
+ client = Client(
105
+ base_url="https://api.example.com",
106
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
107
+ )
108
+
109
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
110
+ ```
111
+
112
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
113
+
114
+ ```python
115
+ import httpx
116
+ from tweetapi_sdk import Client
117
+
118
+ client = Client(
119
+ base_url="https://api.example.com",
120
+ )
121
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
122
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
123
+ ```
124
+
125
+ ## Building / publishing this package
126
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
127
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
128
+ 1. If you're using a private repository, configure it with Poetry
129
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
130
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
131
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
132
+
133
+ If you want to install this client into another project without publishing it (e.g. for development) then:
134
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
135
+ 1. If that project is not using Poetry:
136
+ 1. Build a wheel with `poetry build -f wheel`
137
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
138
+
@@ -0,0 +1,123 @@
1
+ # tweetapi-sdk
2
+ A client library for accessing tweetapi.dev API
3
+
4
+ ## Usage
5
+ First, create a client:
6
+
7
+ ```python
8
+ from tweetapi_sdk 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 tweetapi_sdk 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 tweetapi_sdk.models import MyDataModel
25
+ from tweetapi_sdk.api.my_tag import get_my_data_model
26
+ from tweetapi_sdk.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 tweetapi_sdk.models import MyDataModel
38
+ from tweetapi_sdk.api.my_tag import get_my_data_model
39
+ from tweetapi_sdk.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(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
60
+ ```
61
+
62
+ Things to know:
63
+ 1. Every path/method combo becomes a Python module with four functions:
64
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
65
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
66
+ 1. `asyncio`: Like `sync` but async instead of blocking
67
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
68
+
69
+ 1. All path/query params, and bodies become method arguments.
70
+ 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)
71
+ 1. Any endpoint which did not have a tag will be in `tweetapi_sdk.api.default`
72
+
73
+ ## Advanced customizations
74
+
75
+ 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):
76
+
77
+ ```python
78
+ from tweetapi_sdk import Client
79
+
80
+
81
+ def log_request(request):
82
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
83
+
84
+
85
+ def log_response(response):
86
+ request = response.request
87
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
88
+
89
+
90
+ client = Client(
91
+ base_url="https://api.example.com",
92
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
93
+ )
94
+
95
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
96
+ ```
97
+
98
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
99
+
100
+ ```python
101
+ import httpx
102
+ from tweetapi_sdk import Client
103
+
104
+ client = Client(
105
+ base_url="https://api.example.com",
106
+ )
107
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
108
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
109
+ ```
110
+
111
+ ## Building / publishing this package
112
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
113
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
114
+ 1. If you're using a private repository, configure it with Poetry
115
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
116
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
117
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
118
+
119
+ If you want to install this client into another project without publishing it (e.g. for development) then:
120
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
121
+ 1. If that project is not using Poetry:
122
+ 1. Build a wheel with `poetry build -f wheel`
123
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
@@ -0,0 +1,25 @@
1
+ [tool.poetry]
2
+ name = "tweetapi-sdk"
3
+ version = "0.1.0"
4
+ description = "A client library for accessing tweetapi.dev API"
5
+ authors = []
6
+ readme = "README.md"
7
+ packages = [
8
+ { include = "tweetapi_sdk" },
9
+ ]
10
+ include = ["tweetapi_sdk/py.typed"]
11
+
12
+ [tool.poetry.dependencies]
13
+ python = "^3.11"
14
+ httpx = ">=0.23.1,<0.29.0"
15
+ attrs = ">=22.2.0"
16
+
17
+ [build-system]
18
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
19
+ build-backend = "poetry.core.masonry.api"
20
+
21
+ [tool.ruff]
22
+ line-length = 120
23
+
24
+ [tool.ruff.lint]
25
+ select = ["F", "I", "UP"]
@@ -0,0 +1,8 @@
1
+ """A client library for accessing tweetapi.dev API"""
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,134 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.error import Error
9
+ from ...models.get_me_response_200 import GetMeResponse200
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs() -> dict[str, Any]:
14
+
15
+ _kwargs: dict[str, Any] = {
16
+ "method": "get",
17
+ "url": "/v1/me",
18
+ }
19
+
20
+ return _kwargs
21
+
22
+
23
+ def _parse_response(
24
+ *, client: AuthenticatedClient | Client, response: httpx.Response
25
+ ) -> Error | GetMeResponse200 | None:
26
+ if response.status_code == 200:
27
+ response_200 = GetMeResponse200.from_dict(response.json())
28
+
29
+ return response_200
30
+
31
+ if response.status_code == 401:
32
+ response_401 = Error.from_dict(response.json())
33
+
34
+ return response_401
35
+
36
+ if client.raise_on_unexpected_status:
37
+ raise errors.UnexpectedStatus(response.status_code, response.content)
38
+ else:
39
+ return None
40
+
41
+
42
+ def _build_response(
43
+ *, client: AuthenticatedClient | Client, response: httpx.Response
44
+ ) -> Response[Error | GetMeResponse200]:
45
+ return Response(
46
+ status_code=HTTPStatus(response.status_code),
47
+ content=response.content,
48
+ headers=response.headers,
49
+ parsed=_parse_response(client=client, response=response),
50
+ )
51
+
52
+
53
+ def sync_detailed(
54
+ *,
55
+ client: AuthenticatedClient | Client,
56
+ ) -> Response[Error | GetMeResponse200]:
57
+ """Key, balance and rate limit
58
+
59
+ Raises:
60
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
61
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
62
+
63
+ Returns:
64
+ Response[Error | GetMeResponse200]
65
+ """
66
+
67
+ kwargs = _get_kwargs()
68
+
69
+ response = client.get_httpx_client().request(
70
+ **kwargs,
71
+ )
72
+
73
+ return _build_response(client=client, response=response)
74
+
75
+
76
+ def sync(
77
+ *,
78
+ client: AuthenticatedClient | Client,
79
+ ) -> Error | GetMeResponse200 | None:
80
+ """Key, balance and rate limit
81
+
82
+ Raises:
83
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
84
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
85
+
86
+ Returns:
87
+ Error | GetMeResponse200
88
+ """
89
+
90
+ return sync_detailed(
91
+ client=client,
92
+ ).parsed
93
+
94
+
95
+ async def asyncio_detailed(
96
+ *,
97
+ client: AuthenticatedClient | Client,
98
+ ) -> Response[Error | GetMeResponse200]:
99
+ """Key, balance and rate limit
100
+
101
+ Raises:
102
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
103
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
104
+
105
+ Returns:
106
+ Response[Error | GetMeResponse200]
107
+ """
108
+
109
+ kwargs = _get_kwargs()
110
+
111
+ response = await client.get_async_httpx_client().request(**kwargs)
112
+
113
+ return _build_response(client=client, response=response)
114
+
115
+
116
+ async def asyncio(
117
+ *,
118
+ client: AuthenticatedClient | Client,
119
+ ) -> Error | GetMeResponse200 | None:
120
+ """Key, balance and rate limit
121
+
122
+ Raises:
123
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
124
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
125
+
126
+ Returns:
127
+ Error | GetMeResponse200
128
+ """
129
+
130
+ return (
131
+ await asyncio_detailed(
132
+ client=client,
133
+ )
134
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,187 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.create_checkout_body import CreateCheckoutBody
9
+ from ...models.create_checkout_response_200 import CreateCheckoutResponse200
10
+ from ...models.error import Error
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: CreateCheckoutBody,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/v1/billing/checkout",
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: AuthenticatedClient | Client, response: httpx.Response
35
+ ) -> CreateCheckoutResponse200 | Error | None:
36
+ if response.status_code == 200:
37
+ response_200 = CreateCheckoutResponse200.from_dict(response.json())
38
+
39
+ return response_200
40
+
41
+ if response.status_code == 400:
42
+ response_400 = Error.from_dict(response.json())
43
+
44
+ return response_400
45
+
46
+ if response.status_code == 503:
47
+ response_503 = Error.from_dict(response.json())
48
+
49
+ return response_503
50
+
51
+ if client.raise_on_unexpected_status:
52
+ raise errors.UnexpectedStatus(response.status_code, response.content)
53
+ else:
54
+ return None
55
+
56
+
57
+ def _build_response(
58
+ *, client: AuthenticatedClient | Client, response: httpx.Response
59
+ ) -> Response[CreateCheckoutResponse200 | Error]:
60
+ return Response(
61
+ status_code=HTTPStatus(response.status_code),
62
+ content=response.content,
63
+ headers=response.headers,
64
+ parsed=_parse_response(client=client, response=response),
65
+ )
66
+
67
+
68
+ def sync_detailed(
69
+ *,
70
+ client: AuthenticatedClient | Client,
71
+ body: CreateCheckoutBody,
72
+ ) -> Response[CreateCheckoutResponse200 | Error]:
73
+ """Buy a credit pack
74
+
75
+ Returns a Stripe Checkout URL. Open it in a browser; after payment the credits land in the wallet of
76
+ the
77
+ key's account within seconds and the rate limit rises to the pack's. Credits are valid 12 months.
78
+
79
+ Args:
80
+ body (CreateCheckoutBody):
81
+
82
+ Raises:
83
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
84
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
85
+
86
+ Returns:
87
+ Response[CreateCheckoutResponse200 | Error]
88
+ """
89
+
90
+ kwargs = _get_kwargs(
91
+ body=body,
92
+ )
93
+
94
+ response = client.get_httpx_client().request(
95
+ **kwargs,
96
+ )
97
+
98
+ return _build_response(client=client, response=response)
99
+
100
+
101
+ def sync(
102
+ *,
103
+ client: AuthenticatedClient | Client,
104
+ body: CreateCheckoutBody,
105
+ ) -> CreateCheckoutResponse200 | Error | None:
106
+ """Buy a credit pack
107
+
108
+ Returns a Stripe Checkout URL. Open it in a browser; after payment the credits land in the wallet of
109
+ the
110
+ key's account within seconds and the rate limit rises to the pack's. Credits are valid 12 months.
111
+
112
+ Args:
113
+ body (CreateCheckoutBody):
114
+
115
+ Raises:
116
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
117
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
118
+
119
+ Returns:
120
+ CreateCheckoutResponse200 | Error
121
+ """
122
+
123
+ return sync_detailed(
124
+ client=client,
125
+ body=body,
126
+ ).parsed
127
+
128
+
129
+ async def asyncio_detailed(
130
+ *,
131
+ client: AuthenticatedClient | Client,
132
+ body: CreateCheckoutBody,
133
+ ) -> Response[CreateCheckoutResponse200 | Error]:
134
+ """Buy a credit pack
135
+
136
+ Returns a Stripe Checkout URL. Open it in a browser; after payment the credits land in the wallet of
137
+ the
138
+ key's account within seconds and the rate limit rises to the pack's. Credits are valid 12 months.
139
+
140
+ Args:
141
+ body (CreateCheckoutBody):
142
+
143
+ Raises:
144
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
145
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
146
+
147
+ Returns:
148
+ Response[CreateCheckoutResponse200 | Error]
149
+ """
150
+
151
+ kwargs = _get_kwargs(
152
+ body=body,
153
+ )
154
+
155
+ response = await client.get_async_httpx_client().request(**kwargs)
156
+
157
+ return _build_response(client=client, response=response)
158
+
159
+
160
+ async def asyncio(
161
+ *,
162
+ client: AuthenticatedClient | Client,
163
+ body: CreateCheckoutBody,
164
+ ) -> CreateCheckoutResponse200 | Error | None:
165
+ """Buy a credit pack
166
+
167
+ Returns a Stripe Checkout URL. Open it in a browser; after payment the credits land in the wallet of
168
+ the
169
+ key's account within seconds and the rate limit rises to the pack's. Credits are valid 12 months.
170
+
171
+ Args:
172
+ body (CreateCheckoutBody):
173
+
174
+ Raises:
175
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
176
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
177
+
178
+ Returns:
179
+ CreateCheckoutResponse200 | Error
180
+ """
181
+
182
+ return (
183
+ await asyncio_detailed(
184
+ client=client,
185
+ body=body,
186
+ )
187
+ ).parsed