Model C structs with Pydantic
Project description
CModel
Model C structs with Pydantic
cmodel lets you describe C-compatible binary layouts with normal Pydantic models.
You keep Pydantic's validation and nested models, and gain a simple way to pack and
unpack structs from binary buffers.
Quick start
from io import BytesIO
from cmodel import CModel
from cmodel.types import Int
class Point(CModel):
x: Int
y: Int
buf = BytesIO()
Point(x=3, y=7).c_pack(buf)
buf.seek(0)
point = Point.c_unpack(buf)
assert point == Point(x=3, y=7)
assert buf.getvalue() == b"\x03\x00\x00\x00\x07\x00\x00\x00"
What CModel provides
- Typed field aliases for common C scalar formats such as
Int,Float, andBool - Repeated field formats such as
Annotated[tuple[int, int, int], c_int(3)] - Nested structs by nesting
CModelsubclasses - Explicit packed layouts with
c_alignment=1 - Custom field encodings with
CFmt
Documentation
The documentation site includes:
- A guided first example for getting started
- Practical guides for layout control and custom formats
- API reference for the public modules
- Conceptual explanation of how Pydantic validation maps to binary layout
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
cmodel-0.0.2.tar.gz
(8.8 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 cmodel-0.0.2.tar.gz.
File metadata
- Download URL: cmodel-0.0.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c944dd4128c33b2fa927979818c6046f615ee221f2ff48197bbb3c02b02c9a34
|
|
| MD5 |
af30684251d7d0a2344d942d3f2d0fa9
|
|
| BLAKE2b-256 |
862136866cf9bca7133cfadc700b0c5142aa8645fc6e60c69f912203bad8ba27
|
File details
Details for the file cmodel-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cmodel-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
725ae6dd44e8082e42756b51b0ed9035d34a9dc1baf2a4c826b011d6e9a083d0
|
|
| MD5 |
0a873bfa4bfcc9750a8a51978f7c3fa4
|
|
| BLAKE2b-256 |
9ede68abc8d9cdcffe0ffd80cf3bc837253e74e494df13fe12d16627ff9fcd49
|