A set of pydantic utilities, to extend models on package load
Project description
pydantic-modelable
A set of utilities around pydantic that allows to create extensible pydantic models, with little code, in an aim to have models extended by third-party python code.
Features
Using pydantic for type modelisation and validation has become a very common
practice. That being said, some advanced uses are not natively supported,
although the pydantic types are extremely flexible, such as dynamic
extensibility of the models.
It can be very useful to define extensible models relying on this mechanism,
and pydantic_modelable, as it may provide the following benefits:
- Reduction of code maintenance (defining an "extension" registers it automatically wherever the base was setup)
- Easy extension of a core library's models and features through the loading of extension modules
- Automatically updated Model schemas for inclusion in any schema-based tooling or framework (ex: FastAPI's OpenAPI Schema generation tooling)
With a few additional parameters to your model's constructor, inheriting from
pydantic_modelable.Modelable, you can thus configure specific behaviors for
your extensible model:
- discriminated union:
discriminator=attr_name
You can then register other models into your base model using decorators
embedded into your base model by the pydantic_modelable.Modelable class:
extends_enumextends_union(dicriminated_union_attr_name: str)as_attribute(attr_name: str, optional: bool, default_factory: Callable[[], BaseModel])
Limitations
As pydantic-modelable relies on altering the pydantic models at runtime, the
type-checking tools are usually not able to understand that the model was
extended and its type signature was changed. This, sadly, often leads to an
extensive use of #type: ignore directives in the code relating to the use
of the extended models.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_modelable-0.1.1.tar.gz.
File metadata
- Download URL: pydantic_modelable-0.1.1.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4cbc9cebd997803090217ccd4dcc93596d798061cec1dc606965a9efa25e946
|
|
| MD5 |
7a3da48204e3ec27a33becb09c8ade93
|
|
| BLAKE2b-256 |
05ca23b42cb82fa181185bcb40398e62caddd42c52fc857e408cf0fd665ffab7
|
Provenance
The following attestation bundles were made for pydantic_modelable-0.1.1.tar.gz:
Publisher:
workflow.yml on Joacchim/pydantic-modelable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_modelable-0.1.1.tar.gz -
Subject digest:
f4cbc9cebd997803090217ccd4dcc93596d798061cec1dc606965a9efa25e946 - Sigstore transparency entry: 747768610
- Sigstore integration time:
-
Permalink:
Joacchim/pydantic-modelable@79d13c9084ff4825081fa09566f97f7680cb6323 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Joacchim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@79d13c9084ff4825081fa09566f97f7680cb6323 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_modelable-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pydantic_modelable-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37172acda16e2dba7ce1e675e86656b3ae946ae2fa37f46848b2b4e6239c188a
|
|
| MD5 |
2575562b2cccb37f0249e9956df30691
|
|
| BLAKE2b-256 |
8d5726f8e805e0f9b5a54cf683d3d9cdbbd99afa1dda3ad57ac167be746040ed
|
Provenance
The following attestation bundles were made for pydantic_modelable-0.1.1-py3-none-any.whl:
Publisher:
workflow.yml on Joacchim/pydantic-modelable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_modelable-0.1.1-py3-none-any.whl -
Subject digest:
37172acda16e2dba7ce1e675e86656b3ae946ae2fa37f46848b2b4e6239c188a - Sigstore transparency entry: 747768615
- Sigstore integration time:
-
Permalink:
Joacchim/pydantic-modelable@79d13c9084ff4825081fa09566f97f7680cb6323 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Joacchim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@79d13c9084ff4825081fa09566f97f7680cb6323 -
Trigger Event:
push
-
Statement type: