open-spanner 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 (65) hide show
  1. open_spanner-0.1.0/PKG-INFO +132 -0
  2. open_spanner-0.1.0/README.md +123 -0
  3. open_spanner-0.1.0/open_spanner_client/__init__.py +8 -0
  4. open_spanner-0.1.0/open_spanner_client/api/__init__.py +1 -0
  5. open_spanner-0.1.0/open_spanner_client/api/health/__init__.py +1 -0
  6. open_spanner-0.1.0/open_spanner_client/api/health/health_check.py +81 -0
  7. open_spanner-0.1.0/open_spanner_client/api/meters/__init__.py +1 -0
  8. open_spanner-0.1.0/open_spanner_client/api/meters/create_meter.py +174 -0
  9. open_spanner-0.1.0/open_spanner_client/api/meters/delete_meter.py +165 -0
  10. open_spanner-0.1.0/open_spanner_client/api/meters/get_meter.py +164 -0
  11. open_spanner-0.1.0/open_spanner_client/api/meters/list_meter_stats.py +186 -0
  12. open_spanner-0.1.0/open_spanner_client/api/meters/list_meters.py +201 -0
  13. open_spanner-0.1.0/open_spanner_client/api/meters/update_meter.py +190 -0
  14. open_spanner-0.1.0/open_spanner_client/api/subjects/__init__.py +1 -0
  15. open_spanner-0.1.0/open_spanner_client/api/subjects/list_subject_usage_events.py +192 -0
  16. open_spanner-0.1.0/open_spanner_client/api/subjects/list_subjects.py +186 -0
  17. open_spanner-0.1.0/open_spanner_client/api/system/__init__.py +1 -0
  18. open_spanner-0.1.0/open_spanner_client/api/system/get_system_stats.py +134 -0
  19. open_spanner-0.1.0/open_spanner_client/api/usage_events/__init__.py +1 -0
  20. open_spanner-0.1.0/open_spanner_client/api/usage_events/export_usage_events.py +225 -0
  21. open_spanner-0.1.0/open_spanner_client/api/usage_events/list_prune_runs.py +186 -0
  22. open_spanner-0.1.0/open_spanner_client/api/usage_events/list_usage_events.py +246 -0
  23. open_spanner-0.1.0/open_spanner_client/api/usage_events/prune_usage_events.py +171 -0
  24. open_spanner-0.1.0/open_spanner_client/api/usages/__init__.py +1 -0
  25. open_spanner-0.1.0/open_spanner_client/api/usages/create_usage.py +181 -0
  26. open_spanner-0.1.0/open_spanner_client/api/usages/create_usage_bulk.py +199 -0
  27. open_spanner-0.1.0/open_spanner_client/api/usages/export_usage_buckets.py +260 -0
  28. open_spanner-0.1.0/open_spanner_client/api/usages/list_ingestion_runs.py +186 -0
  29. open_spanner-0.1.0/open_spanner_client/api/usages/list_usage_buckets.py +271 -0
  30. open_spanner-0.1.0/open_spanner_client/client.py +268 -0
  31. open_spanner-0.1.0/open_spanner_client/errors.py +16 -0
  32. open_spanner-0.1.0/open_spanner_client/models/__init__.py +65 -0
  33. open_spanner-0.1.0/open_spanner_client/models/error_body.py +70 -0
  34. open_spanner-0.1.0/open_spanner_client/models/error_response.py +74 -0
  35. open_spanner-0.1.0/open_spanner_client/models/meter.py +137 -0
  36. open_spanner-0.1.0/open_spanner_client/models/meter_create_request.py +119 -0
  37. open_spanner-0.1.0/open_spanner_client/models/meter_create_request_metadata_schema.py +47 -0
  38. open_spanner-0.1.0/open_spanner_client/models/meter_list_response.py +88 -0
  39. open_spanner-0.1.0/open_spanner_client/models/meter_metadata_schema.py +47 -0
  40. open_spanner-0.1.0/open_spanner_client/models/meter_stats.py +88 -0
  41. open_spanner-0.1.0/open_spanner_client/models/meter_stats_list_response.py +88 -0
  42. open_spanner-0.1.0/open_spanner_client/models/meter_update_request.py +61 -0
  43. open_spanner-0.1.0/open_spanner_client/models/subject_stats.py +88 -0
  44. open_spanner-0.1.0/open_spanner_client/models/subject_stats_list_response.py +88 -0
  45. open_spanner-0.1.0/open_spanner_client/models/subject_usage_event.py +137 -0
  46. open_spanner-0.1.0/open_spanner_client/models/subject_usage_event_metadata.py +47 -0
  47. open_spanner-0.1.0/open_spanner_client/models/system_last_prune_run.py +88 -0
  48. open_spanner-0.1.0/open_spanner_client/models/system_stats.py +101 -0
  49. open_spanner-0.1.0/open_spanner_client/models/usage_bucket.py +137 -0
  50. open_spanner-0.1.0/open_spanner_client/models/usage_bucket_group.py +47 -0
  51. open_spanner-0.1.0/open_spanner_client/models/usage_bulk_failure.py +79 -0
  52. open_spanner-0.1.0/open_spanner_client/models/usage_bulk_result.py +150 -0
  53. open_spanner-0.1.0/open_spanner_client/models/usage_create_request.py +119 -0
  54. open_spanner-0.1.0/open_spanner_client/models/usage_create_request_metadata.py +47 -0
  55. open_spanner-0.1.0/open_spanner_client/models/usage_event.py +137 -0
  56. open_spanner-0.1.0/open_spanner_client/models/usage_event_list_response.py +88 -0
  57. open_spanner-0.1.0/open_spanner_client/models/usage_event_metadata.py +47 -0
  58. open_spanner-0.1.0/open_spanner_client/models/usage_ingestion_list_response.py +88 -0
  59. open_spanner-0.1.0/open_spanner_client/models/usage_ingestion_run.py +106 -0
  60. open_spanner-0.1.0/open_spanner_client/models/usage_prune_list_response.py +88 -0
  61. open_spanner-0.1.0/open_spanner_client/models/usage_prune_meter.py +79 -0
  62. open_spanner-0.1.0/open_spanner_client/models/usage_prune_run.py +115 -0
  63. open_spanner-0.1.0/open_spanner_client/py.typed +1 -0
  64. open_spanner-0.1.0/open_spanner_client/types.py +54 -0
  65. open_spanner-0.1.0/pyproject.toml +25 -0
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.3
2
+ Name: open-spanner
3
+ Version: 0.1.0
4
+ Summary: A client library for accessing Open Spanner API
5
+ Requires-Dist: httpx>=0.23.1,<0.29.0
6
+ Requires-Dist: attrs>=22.2.0
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+
10
+ # open-spanner
11
+ A client library for accessing Open Spanner API
12
+
13
+ ## Usage
14
+ First, create a client:
15
+
16
+ ```python
17
+ from open_spanner_client import Client
18
+
19
+ client = Client(base_url="https://api.example.com")
20
+ ```
21
+
22
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
23
+
24
+ ```python
25
+ from open_spanner_client import AuthenticatedClient
26
+
27
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
28
+ ```
29
+
30
+ Now call your endpoint and use your models:
31
+
32
+ ```python
33
+ from open_spanner_client.models import MyDataModel
34
+ from open_spanner_client.api.my_tag import get_my_data_model
35
+ from open_spanner_client.types import Response
36
+
37
+ with client as client:
38
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
39
+ # or if you need more info (e.g. status_code)
40
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
41
+ ```
42
+
43
+ Or do the same thing with an async version:
44
+
45
+ ```python
46
+ from open_spanner_client.models import MyDataModel
47
+ from open_spanner_client.api.my_tag import get_my_data_model
48
+ from open_spanner_client.types import Response
49
+
50
+ async with client as client:
51
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
52
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
53
+ ```
54
+
55
+ 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.
56
+
57
+ ```python
58
+ client = AuthenticatedClient(
59
+ base_url="https://internal_api.example.com",
60
+ token="SuperSecretToken",
61
+ verify_ssl="/path/to/certificate_bundle.pem",
62
+ )
63
+ ```
64
+
65
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
66
+
67
+ ```python
68
+ client = AuthenticatedClient(
69
+ base_url="https://internal_api.example.com",
70
+ token="SuperSecretToken",
71
+ verify_ssl=False
72
+ )
73
+ ```
74
+
75
+ Things to know:
76
+ 1. Every path/method combo becomes a Python module with four functions:
77
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
78
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
79
+ 1. `asyncio`: Like `sync` but async instead of blocking
80
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
81
+
82
+ 1. All path/query params, and bodies become method arguments.
83
+ 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)
84
+ 1. Any endpoint which did not have a tag will be in `open_spanner_client.api.default`
85
+
86
+ ## Advanced customizations
87
+
88
+ 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):
89
+
90
+ ```python
91
+ from open_spanner_client import Client
92
+
93
+ def log_request(request):
94
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
95
+
96
+ def log_response(response):
97
+ request = response.request
98
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
99
+
100
+ client = Client(
101
+ base_url="https://api.example.com",
102
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
103
+ )
104
+
105
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
106
+ ```
107
+
108
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
109
+
110
+ ```python
111
+ import httpx
112
+ from open_spanner_client import Client
113
+
114
+ client = Client(
115
+ base_url="https://api.example.com",
116
+ )
117
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
118
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
119
+ ```
120
+
121
+ ## Building / publishing this package
122
+ This project uses [uv](https://github.com/astral-sh/uv) to manage dependencies and packaging. Here are the basics:
123
+ 1. Update the metadata in `pyproject.toml` (e.g. authors, version).
124
+ 2. If you're using a private repository: https://docs.astral.sh/uv/guides/integration/alternative-indexes/
125
+ 3. Build a distribution with `uv build`, builds `sdist` and `wheel` by default.
126
+ 1. Publish the client with `uv publish`, see documentation for publishing to private indexes.
127
+
128
+ If you want to install this client into another project without publishing it (e.g. for development) then:
129
+ 1. If that project **is using uv**, you can simply do `uv add <path-to-this-client>` from that project
130
+ 1. If that project is not using uv:
131
+ 1. Build a wheel with `uv build --wheel`.
132
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`.
@@ -0,0 +1,123 @@
1
+ # open-spanner
2
+ A client library for accessing Open Spanner API
3
+
4
+ ## Usage
5
+ First, create a client:
6
+
7
+ ```python
8
+ from open_spanner_client 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 open_spanner_client 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 open_spanner_client.models import MyDataModel
25
+ from open_spanner_client.api.my_tag import get_my_data_model
26
+ from open_spanner_client.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 open_spanner_client.models import MyDataModel
38
+ from open_spanner_client.api.my_tag import get_my_data_model
39
+ from open_spanner_client.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 `open_spanner_client.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 open_spanner_client 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 open_spanner_client 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 [uv](https://github.com/astral-sh/uv) to manage dependencies and packaging. Here are the basics:
114
+ 1. Update the metadata in `pyproject.toml` (e.g. authors, version).
115
+ 2. If you're using a private repository: https://docs.astral.sh/uv/guides/integration/alternative-indexes/
116
+ 3. Build a distribution with `uv build`, builds `sdist` and `wheel` by default.
117
+ 1. Publish the client with `uv publish`, see documentation for publishing to private indexes.
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 uv**, you can simply do `uv add <path-to-this-client>` from that project
121
+ 1. If that project is not using uv:
122
+ 1. Build a wheel with `uv build --wheel`.
123
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`.
@@ -0,0 +1,8 @@
1
+ """A client library for accessing Open Spanner 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,81 @@
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 ...types import Response
9
+
10
+
11
+ def _get_kwargs() -> dict[str, Any]:
12
+
13
+ _kwargs: dict[str, Any] = {
14
+ "method": "get",
15
+ "url": "/health",
16
+ }
17
+
18
+ return _kwargs
19
+
20
+
21
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None:
22
+ if response.status_code == 204:
23
+ return None
24
+
25
+ if client.raise_on_unexpected_status:
26
+ raise errors.UnexpectedStatus(response.status_code, response.content)
27
+ else:
28
+ return None
29
+
30
+
31
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]:
32
+ return Response(
33
+ status_code=HTTPStatus(response.status_code),
34
+ content=response.content,
35
+ headers=response.headers,
36
+ parsed=_parse_response(client=client, response=response),
37
+ )
38
+
39
+
40
+ def sync_detailed(
41
+ *,
42
+ client: AuthenticatedClient | Client,
43
+ ) -> Response[Any]:
44
+ """Health check
45
+
46
+ Raises:
47
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
48
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
49
+
50
+ Returns:
51
+ Response[Any]
52
+ """
53
+
54
+ kwargs = _get_kwargs()
55
+
56
+ response = client.get_httpx_client().request(
57
+ **kwargs,
58
+ )
59
+
60
+ return _build_response(client=client, response=response)
61
+
62
+
63
+ async def asyncio_detailed(
64
+ *,
65
+ client: AuthenticatedClient | Client,
66
+ ) -> Response[Any]:
67
+ """Health check
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[Any]
75
+ """
76
+
77
+ kwargs = _get_kwargs()
78
+
79
+ response = await client.get_async_httpx_client().request(**kwargs)
80
+
81
+ return _build_response(client=client, response=response)
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,174 @@
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_response import ErrorResponse
9
+ from ...models.meter import Meter
10
+ from ...models.meter_create_request import MeterCreateRequest
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: MeterCreateRequest,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/v1/meters",
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(*, client: AuthenticatedClient | Client, response: httpx.Response) -> ErrorResponse | Meter | None:
34
+ if response.status_code == 201:
35
+ response_201 = Meter.from_dict(response.json())
36
+
37
+ return response_201
38
+
39
+ if response.status_code == 400:
40
+ response_400 = ErrorResponse.from_dict(response.json())
41
+
42
+ return response_400
43
+
44
+ if response.status_code == 409:
45
+ response_409 = ErrorResponse.from_dict(response.json())
46
+
47
+ return response_409
48
+
49
+ if response.status_code == 500:
50
+ response_500 = ErrorResponse.from_dict(response.json())
51
+
52
+ return response_500
53
+
54
+ if client.raise_on_unexpected_status:
55
+ raise errors.UnexpectedStatus(response.status_code, response.content)
56
+ else:
57
+ return None
58
+
59
+
60
+ def _build_response(
61
+ *, client: AuthenticatedClient | Client, response: httpx.Response
62
+ ) -> Response[ErrorResponse | Meter]:
63
+ return Response(
64
+ status_code=HTTPStatus(response.status_code),
65
+ content=response.content,
66
+ headers=response.headers,
67
+ parsed=_parse_response(client=client, response=response),
68
+ )
69
+
70
+
71
+ def sync_detailed(
72
+ *,
73
+ client: AuthenticatedClient | Client,
74
+ body: MeterCreateRequest,
75
+ ) -> Response[ErrorResponse | Meter]:
76
+ """Create meter
77
+
78
+ Args:
79
+ body (MeterCreateRequest):
80
+
81
+ Raises:
82
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
83
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
84
+
85
+ Returns:
86
+ Response[ErrorResponse | Meter]
87
+ """
88
+
89
+ kwargs = _get_kwargs(
90
+ body=body,
91
+ )
92
+
93
+ response = client.get_httpx_client().request(
94
+ **kwargs,
95
+ )
96
+
97
+ return _build_response(client=client, response=response)
98
+
99
+
100
+ def sync(
101
+ *,
102
+ client: AuthenticatedClient | Client,
103
+ body: MeterCreateRequest,
104
+ ) -> ErrorResponse | Meter | None:
105
+ """Create meter
106
+
107
+ Args:
108
+ body (MeterCreateRequest):
109
+
110
+ Raises:
111
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
112
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
113
+
114
+ Returns:
115
+ ErrorResponse | Meter
116
+ """
117
+
118
+ return sync_detailed(
119
+ client=client,
120
+ body=body,
121
+ ).parsed
122
+
123
+
124
+ async def asyncio_detailed(
125
+ *,
126
+ client: AuthenticatedClient | Client,
127
+ body: MeterCreateRequest,
128
+ ) -> Response[ErrorResponse | Meter]:
129
+ """Create meter
130
+
131
+ Args:
132
+ body (MeterCreateRequest):
133
+
134
+ Raises:
135
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
136
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
137
+
138
+ Returns:
139
+ Response[ErrorResponse | Meter]
140
+ """
141
+
142
+ kwargs = _get_kwargs(
143
+ body=body,
144
+ )
145
+
146
+ response = await client.get_async_httpx_client().request(**kwargs)
147
+
148
+ return _build_response(client=client, response=response)
149
+
150
+
151
+ async def asyncio(
152
+ *,
153
+ client: AuthenticatedClient | Client,
154
+ body: MeterCreateRequest,
155
+ ) -> ErrorResponse | Meter | None:
156
+ """Create meter
157
+
158
+ Args:
159
+ body (MeterCreateRequest):
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
+ ErrorResponse | Meter
167
+ """
168
+
169
+ return (
170
+ await asyncio_detailed(
171
+ client=client,
172
+ body=body,
173
+ )
174
+ ).parsed
@@ -0,0 +1,165 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, cast
3
+ from urllib.parse import quote
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.error_response import ErrorResponse
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs(
14
+ id: str,
15
+ ) -> dict[str, Any]:
16
+
17
+ _kwargs: dict[str, Any] = {
18
+ "method": "delete",
19
+ "url": "/v1/meters/{id}".format(
20
+ id=quote(str(id), safe=""),
21
+ ),
22
+ }
23
+
24
+ return _kwargs
25
+
26
+
27
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | ErrorResponse | None:
28
+ if response.status_code == 204:
29
+ response_204 = cast(Any, None)
30
+ return response_204
31
+
32
+ if response.status_code == 404:
33
+ response_404 = ErrorResponse.from_dict(response.json())
34
+
35
+ return response_404
36
+
37
+ if response.status_code == 409:
38
+ response_409 = ErrorResponse.from_dict(response.json())
39
+
40
+ return response_409
41
+
42
+ if response.status_code == 500:
43
+ response_500 = ErrorResponse.from_dict(response.json())
44
+
45
+ return response_500
46
+
47
+ if client.raise_on_unexpected_status:
48
+ raise errors.UnexpectedStatus(response.status_code, response.content)
49
+ else:
50
+ return None
51
+
52
+
53
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any | ErrorResponse]:
54
+ return Response(
55
+ status_code=HTTPStatus(response.status_code),
56
+ content=response.content,
57
+ headers=response.headers,
58
+ parsed=_parse_response(client=client, response=response),
59
+ )
60
+
61
+
62
+ def sync_detailed(
63
+ id: str,
64
+ *,
65
+ client: AuthenticatedClient | Client,
66
+ ) -> Response[Any | ErrorResponse]:
67
+ """Delete meter
68
+
69
+ Args:
70
+ id (str):
71
+
72
+ Raises:
73
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
74
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
75
+
76
+ Returns:
77
+ Response[Any | ErrorResponse]
78
+ """
79
+
80
+ kwargs = _get_kwargs(
81
+ id=id,
82
+ )
83
+
84
+ response = client.get_httpx_client().request(
85
+ **kwargs,
86
+ )
87
+
88
+ return _build_response(client=client, response=response)
89
+
90
+
91
+ def sync(
92
+ id: str,
93
+ *,
94
+ client: AuthenticatedClient | Client,
95
+ ) -> Any | ErrorResponse | None:
96
+ """Delete meter
97
+
98
+ Args:
99
+ id (str):
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
+ Any | ErrorResponse
107
+ """
108
+
109
+ return sync_detailed(
110
+ id=id,
111
+ client=client,
112
+ ).parsed
113
+
114
+
115
+ async def asyncio_detailed(
116
+ id: str,
117
+ *,
118
+ client: AuthenticatedClient | Client,
119
+ ) -> Response[Any | ErrorResponse]:
120
+ """Delete meter
121
+
122
+ Args:
123
+ id (str):
124
+
125
+ Raises:
126
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
127
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
128
+
129
+ Returns:
130
+ Response[Any | ErrorResponse]
131
+ """
132
+
133
+ kwargs = _get_kwargs(
134
+ id=id,
135
+ )
136
+
137
+ response = await client.get_async_httpx_client().request(**kwargs)
138
+
139
+ return _build_response(client=client, response=response)
140
+
141
+
142
+ async def asyncio(
143
+ id: str,
144
+ *,
145
+ client: AuthenticatedClient | Client,
146
+ ) -> Any | ErrorResponse | None:
147
+ """Delete meter
148
+
149
+ Args:
150
+ id (str):
151
+
152
+ Raises:
153
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
154
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
155
+
156
+ Returns:
157
+ Any | ErrorResponse
158
+ """
159
+
160
+ return (
161
+ await asyncio_detailed(
162
+ id=id,
163
+ client=client,
164
+ )
165
+ ).parsed