BaseModel for cattrs package which provide (un)structure methods to your models
Project description
cattrs_basemodel
BaseModel for cattrs package which provide (un)structure methods to your models
Usages:
from cattrs_basemodel import BaseModel, define, field
# or import from attrs:
# from attrs import define, field
@define
class Point(BaseModel):
x: int = field(default=0)
y: int = field(default=0)
p = Point(1, 2)
json_ = p.unstructure()
print(json_)
p2 = Point.structure(json_)
print(p2)
or define your own BaseModel:
from cattrs_basemodel import BaseModelFactory, define, field
# or import from attrs:
# from attrs import define, field
MyBaseModel = BaseModelFactory("MyBaseModel",
reg_alias=True, # this and next fields are True by default
reg_datetime=True)
@define
class Point(MyBaseModel):
x: int = field(default=0)
y: int = field(default=0)
Converter and hooks:
from cattrs_basemodel import BaseModel
print(BaseModel.converter) # use like cattrs.Converter
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
cattrs_basemodel-1.0.tar.gz
(3.0 kB
view details)
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 cattrs_basemodel-1.0.tar.gz.
File metadata
- Download URL: cattrs_basemodel-1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a1baf4c402bb90ce914a23ecf5d0549c00a9f3370e7af69e337145b1719655c
|
|
| MD5 |
d6a32cec37175f9f512255ad54956339
|
|
| BLAKE2b-256 |
f016ae904ba2a3dbd760542ee2c948046f9f2c91a89e947ab808e39cbbfe1772
|
File details
Details for the file cattrs_basemodel-1.0-py3-none-any.whl.
File metadata
- Download URL: cattrs_basemodel-1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8b8236972fc38e87fceab381447f0497e95b69b2ddfa652cb42260f47ea7f41
|
|
| MD5 |
0432b4171895a33ba1925b106d93377a
|
|
| BLAKE2b-256 |
d269f1ab65070eb3e86e054780fc234639ad53fa274eb24fa9995599ab124354
|