A lightweight serialization library for Python using MessagePack with type-safe Pydantic models
Project description
tinymsg
A lightweight serialization library for Python using MessagePack with type-safe Pydantic models. This Python instance of the tinymsg serialization library is directly compatible with tinymsg-cpp and tinymsg-rs (coming soon).
Features
- Type-safe: Built on Pydantic for automatic validation and type checking
- Fast: Uses MessagePack for efficient binary serialization
- Simple: Minimal boilerplate - just inherit from
Message - Nested support: Handles nested objects, lists, and dicts automatically
Installation
uv add tinymsg # using uv
pip install tinymsg # using pip
Quick Start
from tinymsg import Message
class Person(Message):
name: str
age: int
email: str
class Team(Message):
name: str
members: list[Person]
active: bool = True
# Create objects
alice = Person(name="Alice", age=30, email="alice@example.com")
bob = Person(name="Bob", age=25, email="bob@example.com")
team = Team(
name="Engineering",
members=[alice, bob]
)
# Serialize to bytes
data = team.pack()
# Deserialize from bytes
restored_team = Team.unpack(data)
print(restored_team.members[0].name) # "Alice"
Development
Recommended Workflow (using uv)
uv is a fast Python package manager and virtualenv manager. Install it first:
curl -LsSf https://astral.sh/uv/install.sh | sh
Setup Development Environment
# Create virtual environment and install all dependencies (including dev dependencies)
uv sync --extra dev
# Alternative: Create venv manually then install
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
Development Commands
# Run tests
uv run pytest
# Run tests with coverage report
uv run pytest --cov=tinymsg --cov-report=html
# Run specific test
uv run pytest tests/test_tinymsg.py::TestBasicSerialization::test_simple_message_roundtrip
# Check code with ruff (linting)
uv run ruff check .
# Auto-fix linting issues
uv run ruff check --fix .
# Format code with ruff
uv run ruff format .
Other Useful Commands
# Add a new dependency
uv add requests
# Add a new dev dependency
uv add --dev mypy
# Update dependencies
uv sync
# Show installed packages
uv pip list
Traditional Workflow (using pip)
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Lint and format code
ruff check .
ruff format .
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 tinymsg-0.1.0.tar.gz.
File metadata
- Download URL: tinymsg-0.1.0.tar.gz
- Upload date:
- Size: 80.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
544b39e59e5cce49e5d855bbe0dcfde596678596173bd2bc7be66394c2551d28
|
|
| MD5 |
583648aa27493e859f7a30340bd1f2af
|
|
| BLAKE2b-256 |
1827e3e42577b24b0c4eb151faf55b8f5b22dd77c14c5bf2f35baed3ee2d3315
|
File details
Details for the file tinymsg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tinymsg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e11d2667ef0f440e522ad30e75d597e284be5a135153cb3b0c81cf0016d2c621
|
|
| MD5 |
10117fb0036021faffabfed04fdc9636
|
|
| BLAKE2b-256 |
7570b463f939720c21583b4e299f548f8e256bc1ccaa75417a670b8e0608c93f
|