Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

benzene-pydantic

Validate a Benzene handler's request with a pydantic model — the Python ecosystem's standard for parsing and validating request data — for the Benzene Python port.

Depends on benzene-core and pydantic. The core stays pydantic-free; this optional adapter is the one place the dependency lives.

pip install benzene-pydantic
from benzene.core import message
from benzene.pydantic import validated
from benzene.results import Result
from pydantic import BaseModel

class PlaceOrder(BaseModel):
    sku: str
    quantity: int = 1

@message("orders:place")          # no request_type — the raw body flows in and @validated checks it
@validated(PlaceOrder)
async def place(order: PlaceOrder) -> Result:
    return Result.created(order)  # a pydantic model returned as payload serializes on the wire

@validated(Model) validates the decoded body into Model before your handler runs. A pydantic.ValidationError becomes a validation-error Result carrying one structured error per bad field, so a malformed request never reaches your handler and never crashes the pipeline.

pydantic already knows, per failure, the message, the field it came from and the rule that rejected it, and all three cross into the RFC 9457 problem document unchanged — loc becomes field and pydantic's type becomes code:

// POST {"quantity": "not-an-int"}  ->  status "validation-error"
{
  "type": "https://benzene.app/problems/validation-error",
  "title": "Validation failed",
  "detail": "Field required, Input should be a valid integer, unable to parse string as an integer",
  "benzeneStatus": "validation-error",
  "errors": [
    { "message": "Field required", "field": "sku", "code": "missing" },
    { "message": "Input should be a valid integer, unable to parse string as an integer",
      "field": "quantity", "code": "int_parsing" }
  ]
}

That is the difference between an error a UI can attach to the right input and one it can only print. detail remains the messages joined, for a caller that logs a single line.

benzene.pydantic.validation_errors(exc) exposes the same mapping directly if you validate somewhere other than a handler boundary; format_validation_errors(exc) still returns the flat "field: message" strings.

A pydantic model returned as a success payload is serialized by benzene.core's wire mapper (model_dump(by_alias=True)). Unlike a dataclass — whose fields the mapper auto-camelCases — a pydantic model is dumped under its own field names, so give the model a camelCase alias_generator to cross the wire in the Benzene naming policy (then it matches a dataclass response).

Contributes the benzene.pydantic subpackage to the shared benzene namespace.

Metadata

Release files for benzene-pydantic 0.1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benzene-pydantic 0.1.0b2
File Size Uploaded Provenance Actions
benzene_pydantic-0.1.0b2.tar.gz 6.0 kB With provenance Details for benzene_pydantic-0.1.0b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for benzene-pydantic 0.1.0b2
File Interpreter ABI Platform Actions
benzene_pydantic-0.1.0b2-py3-none-any.whl Python 3 none any Details for benzene_pydantic-0.1.0b2-py3-none-any.whl

Total release size: 13.5 kB

Release files / benzene_pydantic-0.1.0b2.tar.gz

Download URL benzene_pydantic-0.1.0b2.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1d52c56b4687254ed26ec31a0bf028330edc8eb076e1667a84b2084a243fdb6f
BLAKE2b-256 checksum
How to use checksums
8ef917d388bbcaa49e463cee409279fc892983b1831f3c197b063ab14bff08b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / benzene_pydantic-0.1.0b2-py3-none-any.whl

Download URL benzene_pydantic-0.1.0b2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36b9fb646c47b7c2913b39423d7efbbdf02692ebeae4f0e6171ee8cdd3837617
BLAKE2b-256 checksum
How to use checksums
73d18814447c1813b139ecfaff636406bde1e70ecd67208965fc7fdb16708ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for benzene-pydantic 0.1.0b2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for benzene_pydantic-0.1.0b2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page