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.3.2

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.3.2
File Size Uploaded
pydantic_fixedwidth-0.3.2.tar.gz 64.9 kB Details

Built distribution (wheel)

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

Total release size: 70.2 kB

Release files / pydantic_fixedwidth-0.3.2.tar.gz

Download URL pydantic_fixedwidth-0.3.2.tar.gz
Size 64.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0eae77988a16edbe95abe18582b31cf8c7e9aac5179c5adb1683ca1a64ff9d3e
BLAKE2b-256 checksum
How to use checksums
52ee0ad4b7b6b65fffbd58aaee89b46a20f111e02687ee4a70fda9f00b16b23f
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 Sep 2, 2026.

Transparency log

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

Download URL pydantic_fixedwidth-0.3.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb921b6ea06f69bbb299d4ce5c667817de29af43af31484ccebde2c5a115f617
BLAKE2b-256 checksum
How to use checksums
a6a3f0b47f676a97899e68f32ba543ccb2baf680195dd2a83f16e070a7cf2e7b
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 Sep 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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