A pydantic model subclass that implements Python's dictionary interface.
Project description
pydantic_dictionary
A pydantic
model subclass that implements Python's dictionary interface.
Example:
from pydantic_dict import BaseModelDict
class User(BaseModelDict):
id: int
name: str = "Jane Doe"
user = User(id=42)
user["session_id"] = "95607c42-250a-4913-9dfb-00eb6535e685"
assert user.session_id == "95607c42-250a-4913-9dfb-00eb6535e685"
assert user["session_id"] == "95607c42-250a-4913-9dfb-00eb6535e685"
user.pop("session_id")
assert "session_id" not in user
assert user.get("last_name", None) is None
user.update({"email": "jane.doe@email.com"})
print(user.json())
# >>> {"id": 42, "name": "Jane Doe", "email": "jane.doe@email.com"}
user.clear() # field's are NOT removed. only non-field's are removed
print(user.json())
# >>> {"id": 42, "name": "Jane Doe"}
user.setdefault("last_active", "2023-01-01T19:56:10Z")
del user["last_active"]
Install
pip install pydantic_dict
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
pydantic_dict-0.0.1.tar.gz
(9.3 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_dict-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8380f073aa432d2f0bfebc40a765c17726fedbf66033b3f6603af5e6550c9b91 |
|
MD5 | a64436e8fdc72a3cd02182d4569e6891 |
|
BLAKE2b-256 | c7f936f291a12fa5a8706fe5697905c78ca98d184fe89799bd44be9aa285931e |