patera-apiinterface 0.12.0__tar.gz → 0.13.1__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.
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/PKG-INFO +50 -44
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/README.md +49 -43
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/pyproject.toml +1 -1
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/src/patera/apiinterface/api_interface.py +1187 -1170
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/LICENSE +0 -0
- {patera_apiinterface-0.12.0 → patera_apiinterface-0.13.1}/src/patera/apiinterface/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patera-apiinterface
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.1
|
|
4
4
|
Summary: Declarative async HTTP clients for external APIs in Patera applications
|
|
5
5
|
Keywords: patera,http,client,api
|
|
6
6
|
Author: Marko Šterk
|
|
@@ -27,46 +27,52 @@ Project-URL: Issues, https://github.com/MarkoSterk/Patera/issues
|
|
|
27
27
|
Project-URL: Changelog, https://github.com/MarkoSterk/Patera/blob/main/CHANGELOG.md
|
|
28
28
|
Description-Content-Type: text/markdown
|
|
29
29
|
|
|
30
|
-
# patera-apiinterface
|
|
31
|
-
|
|
32
|
-
Declarative async HTTP clients for external APIs in Patera applications. Part of [Patera](https://github.com/MarkoSterk/Patera), a modular async-first Python web framework.
|
|
33
|
-
|
|
34
|
-
## Installation
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
pip install patera-apiinterface
|
|
38
|
-
# or, with uv
|
|
39
|
-
uv add "patera[apiinterface]"
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Requires Python 3.13 or newer and `patera>=0.121`.
|
|
43
|
-
|
|
44
|
-
## Usage
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
from
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
30
|
+
# patera-apiinterface
|
|
31
|
+
|
|
32
|
+
Declarative async HTTP clients for external APIs in Patera applications. Part of [Patera](https://github.com/MarkoSterk/Patera), a modular async-first Python web framework.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pip install patera-apiinterface
|
|
38
|
+
# or, with uv
|
|
39
|
+
uv add "patera[apiinterface]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Requires Python 3.13 or newer and `patera>=0.121`.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
Within an application lifespan, an interface reuses one HTTP client and closes
|
|
47
|
+
it at shutdown. Standalone and CLI endpoint calls use temporary clients closed
|
|
48
|
+
before the call returns, including failures. If you acquire `interface.client`
|
|
49
|
+
explicitly, call `await interface.aclose()` in that same event loop before it
|
|
50
|
+
closes. Access from another loop raises instead of discarding an unclosed client.
|
|
51
|
+
|
|
52
|
+
`patera-apiinterface` turns annotated methods into HTTP calls (with [HTTPX](https://www.python-httpx.org)):
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from patera import HttpMethod
|
|
56
|
+
from patera.apiinterface import ApiInterface, AuthType, auth, headers, method, resource, service, timeout
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@service("GITHUB_URL") # config key or literal URL
|
|
60
|
+
@auth(AuthType.BEARER, token="GITHUB_TOKEN") # config key or literal value
|
|
61
|
+
@headers({"X-Client": "my-app"})
|
|
62
|
+
@timeout(10)
|
|
63
|
+
class GithubApi(ApiInterface):
|
|
64
|
+
|
|
65
|
+
@method(HttpMethod.GET)
|
|
66
|
+
@resource("/repos/<repo_id>") # filled from the argument of the same name
|
|
67
|
+
async def get_repo(self, repo_id: int) -> Repo: ... # Pydantic return types are validated
|
|
68
|
+
|
|
69
|
+
@method(HttpMethod.POST)
|
|
70
|
+
@resource("/repos")
|
|
71
|
+
async def create_repo(self, name: str, private: bool) -> dict: ... # arguments become the JSON body
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
See the [External APIs section of the Patera documentation](https://github.com/MarkoSterk/Patera#external-apis) for the full guide.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT. See [LICENSE](https://github.com/MarkoSterk/Patera/blob/main/LICENSE).
|
|
@@ -1,43 +1,49 @@
|
|
|
1
|
-
# patera-apiinterface
|
|
2
|
-
|
|
3
|
-
Declarative async HTTP clients for external APIs in Patera applications. Part of [Patera](https://github.com/MarkoSterk/Patera), a modular async-first Python web framework.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
pip install patera-apiinterface
|
|
9
|
-
# or, with uv
|
|
10
|
-
uv add "patera[apiinterface]"
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Requires Python 3.13 or newer and `patera>=0.121`.
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
from
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
# patera-apiinterface
|
|
2
|
+
|
|
3
|
+
Declarative async HTTP clients for external APIs in Patera applications. Part of [Patera](https://github.com/MarkoSterk/Patera), a modular async-first Python web framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install patera-apiinterface
|
|
9
|
+
# or, with uv
|
|
10
|
+
uv add "patera[apiinterface]"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Python 3.13 or newer and `patera>=0.121`.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Within an application lifespan, an interface reuses one HTTP client and closes
|
|
18
|
+
it at shutdown. Standalone and CLI endpoint calls use temporary clients closed
|
|
19
|
+
before the call returns, including failures. If you acquire `interface.client`
|
|
20
|
+
explicitly, call `await interface.aclose()` in that same event loop before it
|
|
21
|
+
closes. Access from another loop raises instead of discarding an unclosed client.
|
|
22
|
+
|
|
23
|
+
`patera-apiinterface` turns annotated methods into HTTP calls (with [HTTPX](https://www.python-httpx.org)):
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from patera import HttpMethod
|
|
27
|
+
from patera.apiinterface import ApiInterface, AuthType, auth, headers, method, resource, service, timeout
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@service("GITHUB_URL") # config key or literal URL
|
|
31
|
+
@auth(AuthType.BEARER, token="GITHUB_TOKEN") # config key or literal value
|
|
32
|
+
@headers({"X-Client": "my-app"})
|
|
33
|
+
@timeout(10)
|
|
34
|
+
class GithubApi(ApiInterface):
|
|
35
|
+
|
|
36
|
+
@method(HttpMethod.GET)
|
|
37
|
+
@resource("/repos/<repo_id>") # filled from the argument of the same name
|
|
38
|
+
async def get_repo(self, repo_id: int) -> Repo: ... # Pydantic return types are validated
|
|
39
|
+
|
|
40
|
+
@method(HttpMethod.POST)
|
|
41
|
+
@resource("/repos")
|
|
42
|
+
async def create_repo(self, name: str, private: bool) -> dict: ... # arguments become the JSON body
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
See the [External APIs section of the Patera documentation](https://github.com/MarkoSterk/Patera#external-apis) for the full guide.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT. See [LICENSE](https://github.com/MarkoSterk/Patera/blob/main/LICENSE).
|