didactic-fastapi 0.14.0__tar.gz → 0.16.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.
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/PKG-INFO +24 -21
- didactic_fastapi-0.16.0/README.md +66 -0
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/pyproject.toml +1 -1
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/src/didactic/fastapi/__init__.py +1 -1
- didactic_fastapi-0.14.0/README.md +0 -63
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/.gitignore +0 -0
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/src/didactic/fastapi/_adapter.py +0 -0
- {didactic_fastapi-0.14.0 → didactic_fastapi-0.16.0}/src/didactic/fastapi/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: didactic-fastapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Summary: FastAPI integration for didactic Models.
|
|
5
5
|
Author-email: Aaron Steven White <aaronstevenwhite@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -19,15 +19,15 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
|
|
20
20
|
# didactic-fastapi
|
|
21
21
|
|
|
22
|
-
*FastAPI integration for `dx.Model` types.*
|
|
23
|
-
|
|
24
22
|
[](https://pypi.org/project/didactic-fastapi/)
|
|
25
23
|
[](https://pypi.org/project/didactic-fastapi/)
|
|
26
24
|
[](https://github.com/panproto/didactic/blob/main/LICENSE)
|
|
27
25
|
[](https://github.com/panproto/didactic/actions/workflows/ci.yml)
|
|
28
26
|
[](https://panproto.dev/didactic/guide/fastapi/)
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
`didactic-fastapi` adapts `dx.Model` classes for FastAPI request validation,
|
|
29
|
+
response validation, and OpenAPI generation. It adds the `didactic.fastapi`
|
|
30
|
+
module and uses `didactic-pydantic` at the framework boundary.
|
|
31
31
|
|
|
32
32
|
## Install
|
|
33
33
|
|
|
@@ -35,15 +35,15 @@ Contributes `didactic.fastapi` to the namespace package.
|
|
|
35
35
|
pip install didactic-fastapi
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
The
|
|
38
|
+
The distribution depends on `didactic`, `didactic-pydantic`, and
|
|
39
39
|
`fastapi>=0.115`.
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## Use a Didactic response model
|
|
42
42
|
|
|
43
43
|
```python
|
|
44
44
|
import didactic.api as dx
|
|
45
|
-
from fastapi import FastAPI
|
|
46
45
|
from didactic.fastapi import as_response, register_validation_handler
|
|
46
|
+
from fastapi import FastAPI
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
class User(dx.Model):
|
|
@@ -55,27 +55,30 @@ app = FastAPI()
|
|
|
55
55
|
register_validation_handler(app)
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
@app.get("/users/{
|
|
59
|
-
def get_user(
|
|
60
|
-
return User(id=
|
|
58
|
+
@app.get("/users/{user_id}", response_model=as_response(User))
|
|
59
|
+
def get_user(user_id: str) -> User:
|
|
60
|
+
return User(id=user_id, email="ada@example.org")
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
`as_response(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
`as_response(User)` returns a cached `pydantic.BaseModel` subclass that mirrors
|
|
64
|
+
`User`. FastAPI uses that class for validation and OpenAPI generation.
|
|
65
|
+
|
|
66
|
+
## Adapter behavior
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
| Function | Behavior |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `as_response(model)` | returns the generated Pydantic class for a response model |
|
|
71
|
+
| `as_request(model)` | returns the same adapter under a request-oriented name |
|
|
72
|
+
| `register_validation_handler(app)` | converts `dx.ValidationError` raised in a route into a FastAPI-style 422 response |
|
|
70
73
|
|
|
71
|
-
`
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
Models with `dx.indexed_by` fields retain their cross-field validation. Their
|
|
75
|
+
known index cases also appear as conditional constraints in the generated
|
|
76
|
+
OpenAPI schema.
|
|
74
77
|
|
|
75
78
|
## Documentation
|
|
76
79
|
|
|
77
|
-
See [
|
|
78
|
-
|
|
80
|
+
See the [FastAPI guide](https://panproto.dev/didactic/guide/fastapi/) for request
|
|
81
|
+
models, response models, error handling, and integration limits.
|
|
79
82
|
|
|
80
83
|
## License
|
|
81
84
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# didactic-fastapi
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/didactic-fastapi/)
|
|
4
|
+
[](https://pypi.org/project/didactic-fastapi/)
|
|
5
|
+
[](https://github.com/panproto/didactic/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/panproto/didactic/actions/workflows/ci.yml)
|
|
7
|
+
[](https://panproto.dev/didactic/guide/fastapi/)
|
|
8
|
+
|
|
9
|
+
`didactic-fastapi` adapts `dx.Model` classes for FastAPI request validation,
|
|
10
|
+
response validation, and OpenAPI generation. It adds the `didactic.fastapi`
|
|
11
|
+
module and uses `didactic-pydantic` at the framework boundary.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pip install didactic-fastapi
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The distribution depends on `didactic`, `didactic-pydantic`, and
|
|
20
|
+
`fastapi>=0.115`.
|
|
21
|
+
|
|
22
|
+
## Use a Didactic response model
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import didactic.api as dx
|
|
26
|
+
from didactic.fastapi import as_response, register_validation_handler
|
|
27
|
+
from fastapi import FastAPI
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class User(dx.Model):
|
|
31
|
+
id: str
|
|
32
|
+
email: str
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
app = FastAPI()
|
|
36
|
+
register_validation_handler(app)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.get("/users/{user_id}", response_model=as_response(User))
|
|
40
|
+
def get_user(user_id: str) -> User:
|
|
41
|
+
return User(id=user_id, email="ada@example.org")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`as_response(User)` returns a cached `pydantic.BaseModel` subclass that mirrors
|
|
45
|
+
`User`. FastAPI uses that class for validation and OpenAPI generation.
|
|
46
|
+
|
|
47
|
+
## Adapter behavior
|
|
48
|
+
|
|
49
|
+
| Function | Behavior |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `as_response(model)` | returns the generated Pydantic class for a response model |
|
|
52
|
+
| `as_request(model)` | returns the same adapter under a request-oriented name |
|
|
53
|
+
| `register_validation_handler(app)` | converts `dx.ValidationError` raised in a route into a FastAPI-style 422 response |
|
|
54
|
+
|
|
55
|
+
Models with `dx.indexed_by` fields retain their cross-field validation. Their
|
|
56
|
+
known index cases also appear as conditional constraints in the generated
|
|
57
|
+
OpenAPI schema.
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
See the [FastAPI guide](https://panproto.dev/didactic/guide/fastapi/) for request
|
|
62
|
+
models, response models, error handling, and integration limits.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
Released under the [MIT License](https://github.com/panproto/didactic/blob/main/LICENSE).
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# didactic-fastapi
|
|
2
|
-
|
|
3
|
-
*FastAPI integration for `dx.Model` types.*
|
|
4
|
-
|
|
5
|
-
[](https://pypi.org/project/didactic-fastapi/)
|
|
6
|
-
[](https://pypi.org/project/didactic-fastapi/)
|
|
7
|
-
[](https://github.com/panproto/didactic/blob/main/LICENSE)
|
|
8
|
-
[](https://github.com/panproto/didactic/actions/workflows/ci.yml)
|
|
9
|
-
[](https://panproto.dev/didactic/guide/fastapi/)
|
|
10
|
-
|
|
11
|
-
Contributes `didactic.fastapi` to the namespace package.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
pip install didactic-fastapi
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
The package depends on `didactic`, `didactic-pydantic`, and
|
|
20
|
-
`fastapi>=0.115`.
|
|
21
|
-
|
|
22
|
-
## Quickstart
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
import didactic.api as dx
|
|
26
|
-
from fastapi import FastAPI
|
|
27
|
-
from didactic.fastapi import as_response, register_validation_handler
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class User(dx.Model):
|
|
31
|
-
id: str
|
|
32
|
-
email: str
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
app = FastAPI()
|
|
36
|
-
register_validation_handler(app)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@app.get("/users/{uid}", response_model=as_response(User))
|
|
40
|
-
def get_user(uid: str) -> User:
|
|
41
|
-
return User(id=uid, email="ada@example.org")
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
`as_response(model)` returns a `pydantic.BaseModel` subclass
|
|
45
|
-
mirroring the input `dx.Model`. FastAPI uses the result for response
|
|
46
|
-
validation and OpenAPI generation. The conversion is cached per input
|
|
47
|
-
class.
|
|
48
|
-
|
|
49
|
-
`as_request(model)` is a synonym; use whichever name reads naturally
|
|
50
|
-
in your route signatures.
|
|
51
|
-
|
|
52
|
-
`register_validation_handler(app)` installs an exception handler so
|
|
53
|
-
that `dx.ValidationError` raised inside a route surfaces as a 422
|
|
54
|
-
response shaped like FastAPI's own validation errors.
|
|
55
|
-
|
|
56
|
-
## Documentation
|
|
57
|
-
|
|
58
|
-
See [Guides > FastAPI](https://panproto.dev/didactic/guide/fastapi/)
|
|
59
|
-
for the full integration guide and caveats.
|
|
60
|
-
|
|
61
|
-
## License
|
|
62
|
-
|
|
63
|
-
Released under the [MIT License](https://github.com/panproto/didactic/blob/main/LICENSE).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|