https://github.com/rmorshea/cmodel
Model C structs with Pydantic
https://github.com/rmorshea/cmodel
c pydantic python
Last synced: 3 months ago
JSON representation
Model C structs with Pydantic
- Host: GitHub
- URL: https://github.com/rmorshea/cmodel
- Owner: rmorshea
- License: mit
- Created: 2026-04-01T06:36:14.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-06T06:54:04.000Z (3 months ago)
- Last Synced: 2026-04-07T22:03:38.887Z (3 months ago)
- Topics: c, pydantic, python
- Language: Python
- Homepage: https://ryanmorshead.com/cmodel/
- Size: 728 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CModel
[](https://pypi.org/project/cmodel)
[](https://pypi.org/project/cmodel)
[](https://opensource.org/licenses/MIT)
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
```python
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"
```