Pydantic BaseModel supercharged with essential methods
Project description
Super Model for Pydantic
I created this package because I needed a centralized place for a Pydantic BaseModel that can 1) return the generic type of the BaseModel and 2) return which field(s) have a certain Annotation.
Installation
Install with pip
pip install super_model
Features
- Generic support
- Able to retrieve field(s) with a specific Annotation
Generic Example
from super_model import BaseModel
class UserWithType[T](BaseModel):
"""User model with a generic type."""
id: T
name: str
user = UserWithType[int](id=1, name="John Doe")
user_type = user.get_type() # int
Annotation Example
from typing import Annotated
from super_model import BaseModel
class _PrimaryKeyAnnotation:
pass
PrimaryKey = Annotated[int, _PrimaryKeyAnnotation]
class UserWithAnnotation(BaseModel):
"""User model with an Annotation for a field."""
id: PrimaryKey
name: str
user = UserWithAnnotation(id=1, name="John Doe")
annotations = user.get_annotated_fields(PrimaryKey)
# {"id": 1}
Project details
Release history Release notifications | RSS feed
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_super_model-0.0.1.tar.gz.
File metadata
- Download URL: pydantic_super_model-0.0.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.11 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1747d3c9bc713ccc816c7238698d68f607c00bee23e287f95051d98455efca54
|
|
| MD5 |
54701c9a7bf87a454395fce27579d89b
|
|
| BLAKE2b-256 |
0affdfd212f0ebef592f7448783bdbfb75386022ebb167d8db873e70c1c6cf6a
|
File details
Details for the file pydantic_super_model-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pydantic_super_model-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.11 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
615dcb2708e50f2c9ce6f11b135af8e493fe9d56fe5dc6ffcc6740653d51284d
|
|
| MD5 |
f2606610620789872b9d9e3db6908a1a
|
|
| BLAKE2b-256 |
5946578d5ee8a5abb05af75e89c69dea866d2130df9b11aa8844c345bbf079b3
|