Metadata-Version: 2.4
Name: pydantic-msgspec
Version: 0.1.1
Summary: Generate msgspec Struct types from Pydantic v2 models (camelCase JSON, optional tag_field unions) and vice-versa.
Project-URL: Documentation, https://pydantic-msgspec.readthedocs.io/en/latest/
Project-URL: Repository, https://gitlab.com/paul/pydantic-msgspec
Project-URL: Changelog, https://gitlab.com/paul/pydantic-msgspec/-/releases
Author: Paul English <paulnglsh@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: json,msgspec,pydantic,serialization,struct
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: msgspec>=0.21.1
Requires-Dist: pydantic>=2.13.3
Provides-Extra: dev
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: furo>=2024.8.6; extra == 'docs'
Requires-Dist: sphinx>=8.0; extra == 'docs'
Description-Content-Type: text/markdown

# pydantic-msgspec

Generate [msgspec](https://github.com/jcrist/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

```bash
pip install pydantic-msgspec
# or
uv add pydantic-msgspec
```

## Usage

```python
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](https://pydantic-msgspec.readthedocs.io/en/latest/).

## Development

```bash
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)

1. On [PyPI](https://pypi.org/manage/account/publishing/) (or TestPyPI), add a **pending publisher** or open your project → **Manage** → **Publishing** → **Add a new pending publisher** / trusted publisher for **GitLab**.
2. Set **GitLab namespace and project** to your path (for example `group/pydantic-msgspec`), **workflow** to **GitLab CI/CD**, and the **correct GitLab hostname** if not `gitlab.com`.
3. Tag a release (`v0.1.0`) so the deploy job in `.gitlab-ci.yml` runs; 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

1. Import the GitLab repository at [readthedocs.org](https://readthedocs.org/).
2. Use the included `.readthedocs.yaml`; set the default branch and Python version as needed.
3. After the first successful build, update PyPI **project URLs** if the docs URL differs from the placeholder in `pyproject.toml`.
