pydantic-msgspec
Generate msgspec Struct types from Pydantic v2 BaseModel classes. Structs use rename="camel" for JSON keys. Models with a single-string Literal role or type field map to msgspec tag_field / tag for tagged unions.
Install
pip install pydantic-msgspec
# or
uv add pydantic-msgspec
Usage
from pydantic import BaseModel
import msgspec
from pydantic_msgspec import msgspec_from_pydantic, pydantic_from_msgspec
class Item(BaseModel):
name: str
count: int = 1
MSItem = msgspec_from_pydantic(Item)
raw = msgspec.json.encode(MSItem(name="x", count=2))
model = pydantic_from_msgspec(Item, MSItem(name="x", count=2))
assert model == Item(name="x", count=2)
Full API reference: Read the Docs.
Development
uv sync --all-extras # dev + docs
uv run pytest --cov=pydantic_msgspec
uv run sphinx-build -W -b html docs docs/_build
For maintainers
PyPI (trusted publishing with GitLab)
- On PyPI (or TestPyPI), add a pending publisher or open your project → Manage → Publishing → Add a new pending publisher / trusted publisher for GitLab.
- Set GitLab namespace and project to your path (for example
group/pydantic-msgspec), workflow to GitLab CI/CD, and the correct GitLab hostname if notgitlab.com. - Tag a release (
v0.1.0) so the deploy job in.gitlab-ci.ymlruns; the pipeline uses OIDC (id_tokens) and twine without long-lived API tokens.
Adjust Repository / Documentation URLs in pyproject.toml to match your real GitLab and Read the Docs project slug.
Read the Docs
- Import the GitLab repository at readthedocs.org.
- Use the included
.readthedocs.yaml; set the default branch and Python version as needed. - After the first successful build, update PyPI project URLs if the docs URL differs from the placeholder in
pyproject.toml.
Metadata
Release files for pydantic-msgspec 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_msgspec-0.1.1.tar.gz | 6.4 kB | Without provenance | Details for pydantic_msgspec-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_msgspec-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pydantic_msgspec-0.1.1-py3-none-any.whl |
Total release size: 12.2 kB
Release files / pydantic_msgspec-0.1.1.tar.gz
| Download URL | pydantic_msgspec-0.1.1.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc792c9de59216c61e128d0371610ea2aa7c68b84eb88ebe9fd0cc80c406e8d3
|
|
BLAKE2b-256 checksum How to use checksums |
ccf0dcdb43db52b24f569dd2490030da126b45554da4fe2b8af0b3880a6cf784
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pydantic_msgspec-0.1.1-py3-none-any.whl
| Download URL | pydantic_msgspec-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b46863495add2d56f2e1f7b4f6f769e6a3bc3aae4eeb2d7191d1f5acd76be1d4
|
|
BLAKE2b-256 checksum How to use checksums |
9a47af80ef12a78044e5d422c6b1f2b365230f9907786a7341bfaf0c00566f25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for pydantic-msgspec 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.