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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: didactic-fastapi
3
- Version: 0.14.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
  [![PyPI](https://img.shields.io/pypi/v/didactic-fastapi?style=flat-square&color=blue)](https://pypi.org/project/didactic-fastapi/)
25
23
  [![Python](https://img.shields.io/pypi/pyversions/didactic-fastapi?style=flat-square)](https://pypi.org/project/didactic-fastapi/)
26
24
  [![License](https://img.shields.io/pypi/l/didactic-fastapi?style=flat-square&color=green)](https://github.com/panproto/didactic/blob/main/LICENSE)
27
25
  [![CI](https://img.shields.io/github/actions/workflow/status/panproto/didactic/ci.yml?branch=main&style=flat-square&label=ci)](https://github.com/panproto/didactic/actions/workflows/ci.yml)
28
26
  [![Docs](https://img.shields.io/badge/docs-panproto.dev-blue?style=flat-square)](https://panproto.dev/didactic/guide/fastapi/)
29
27
 
30
- Contributes `didactic.fastapi` to the namespace package.
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 package depends on `didactic`, `didactic-pydantic`, and
38
+ The distribution depends on `didactic`, `didactic-pydantic`, and
39
39
  `fastapi>=0.115`.
40
40
 
41
- ## Quickstart
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/{uid}", response_model=as_response(User))
59
- def get_user(uid: str) -> User:
60
- return User(id=uid, email="ada@example.org")
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(model)` returns a `pydantic.BaseModel` subclass
64
- mirroring the input `dx.Model`. FastAPI uses the result for response
65
- validation and OpenAPI generation. The conversion is cached per input
66
- class.
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
- `as_request(model)` is a synonym; use whichever name reads naturally
69
- in your route signatures.
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
- `register_validation_handler(app)` installs an exception handler so
72
- that `dx.ValidationError` raised inside a route surfaces as a 422
73
- response shaped like FastAPI's own validation errors.
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 [Guides > FastAPI](https://panproto.dev/didactic/guide/fastapi/)
78
- for the full integration guide and caveats.
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
+ [![PyPI](https://img.shields.io/pypi/v/didactic-fastapi?style=flat-square&color=blue)](https://pypi.org/project/didactic-fastapi/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/didactic-fastapi?style=flat-square)](https://pypi.org/project/didactic-fastapi/)
5
+ [![License](https://img.shields.io/pypi/l/didactic-fastapi?style=flat-square&color=green)](https://github.com/panproto/didactic/blob/main/LICENSE)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/panproto/didactic/ci.yml?branch=main&style=flat-square&label=ci)](https://github.com/panproto/didactic/actions/workflows/ci.yml)
7
+ [![Docs](https://img.shields.io/badge/docs-panproto.dev-blue?style=flat-square)](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).
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "didactic-fastapi"
7
- version = "0.14.0"
7
+ version = "0.16.0"
8
8
  description = "FastAPI integration for didactic Models."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.14"
@@ -23,7 +23,7 @@ from didactic.fastapi._adapter import (
23
23
  register_validation_handler,
24
24
  )
25
25
 
26
- __version__ = "0.14.0"
26
+ __version__ = "0.16.0"
27
27
 
28
28
  __all__ = [
29
29
  "__version__",
@@ -1,63 +0,0 @@
1
- # didactic-fastapi
2
-
3
- *FastAPI integration for `dx.Model` types.*
4
-
5
- [![PyPI](https://img.shields.io/pypi/v/didactic-fastapi?style=flat-square&color=blue)](https://pypi.org/project/didactic-fastapi/)
6
- [![Python](https://img.shields.io/pypi/pyversions/didactic-fastapi?style=flat-square)](https://pypi.org/project/didactic-fastapi/)
7
- [![License](https://img.shields.io/pypi/l/didactic-fastapi?style=flat-square&color=green)](https://github.com/panproto/didactic/blob/main/LICENSE)
8
- [![CI](https://img.shields.io/github/actions/workflow/status/panproto/didactic/ci.yml?branch=main&style=flat-square&label=ci)](https://github.com/panproto/didactic/actions/workflows/ci.yml)
9
- [![Docs](https://img.shields.io/badge/docs-panproto.dev-blue?style=flat-square)](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).