Skip to main content

pydantic-fixedwidth

License: MIT codecov PyPI - Version

Custom Pydantic models for serializing and deserializing fixed-width data.

✨ Features

This small Python package provides tools for working with fixed-width data and for serializing and deserializing it using Pydantic models.

🚀 Quick Start

Install this package with pip:

$ pip install pydantic-fixedwidth

Usage example:

from datetime import datetime, timezone

from pydantic_fixedwidth import Fixedwidth, Padding
from pydantic_fixedwidth import OrderedField as Field

tzinfo = timezone.utc


class SomeRequest(Fixedwidth):
    string: str = Field(length=8)
    hangul: str = Field(length=6)
    number: int = Field(length=10, justify="right", fill_char=b"0")

    # Just an padding field
    p_: str = Padding(length=10)

    # This field will be ignored in ser/de
    ignore: str = Field(length=10, default="IGNORE", exclude=True)

    ts: datetime = Field(
        length=20,
        to_str=lambda dt: dt.strftime("%Y%m%d%H%M%S%f"),
        from_str=lambda s: datetime.strptime(s, "%Y%m%d%H%M%S%f").replace(tzinfo=tzinfo),
    )


# Format model to bytes
some_request = SomeRequest(
    string="<DFG&",
    hangul="한글",
    number=381,
    ts=datetime(2024, 1, 23, 14, 11, 20, 124277, tzinfo=tzinfo),
)
b = some_request.format_bytes()

assert len(b) == 54
assert b == b"<DFG&   \xed\x95\x9c\xea\xb8\x800000000381          20240123141120124277"

# Parse bytes into model
parsed_request = SomeRequest.parse_bytes(b)

assert parsed_request == some_request

💖 Contributing

Please see CONTRIBUTING.md for information on contributing to this project.

📜 License

This project is licensed under the MIT License.

Metadata

Release files for pydantic-fixedwidth 0.4.0

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

Source distribution (sdist)

Source distribution for pydantic-fixedwidth 0.4.0
File Size Uploaded Provenance Actions
pydantic_fixedwidth-0.4.0.tar.gz 66.4 kB With provenance Details for pydantic_fixedwidth-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-fixedwidth 0.4.0
File Interpreter ABI Platform Actions
pydantic_fixedwidth-0.4.0-py3-none-any.whl Python 3 none any Details for pydantic_fixedwidth-0.4.0-py3-none-any.whl

Total release size: 71.7 kB

Release files / pydantic_fixedwidth-0.4.0.tar.gz

Download URL pydantic_fixedwidth-0.4.0.tar.gz
Size 66.4 kB
Tags Source
SHA-256 checksum
How to use checksums
01fb6cedba6009a4daae7099b265fd1b2163035543f4ed5f92726a176e9a3436
BLAKE2b-256 checksum
How to use checksums
f6d2d6e126df13e1fc0ac1386b0f669ead958251aaa2aa8e1e45053f5fa59223
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 26, 2026.

Transparency log

Release files / pydantic_fixedwidth-0.4.0-py3-none-any.whl

Download URL pydantic_fixedwidth-0.4.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c18dbd9d97b10cb3a02361526c85489fd04365bda6ff952de5eaf7c51ba0093
BLAKE2b-256 checksum
How to use checksums
6736ee6741baf86b986317e643d9e8009884a3470a71947f66a2f2ebf4bddf27
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 26, 2026.

Transparency log

Security for pydantic-fixedwidth 0.4.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_fixedwidth-0.4.0.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 26, 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