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