Custom Pydantic models for parsing and serializing fixed-width format of data.
Project description
pydantic-fixedwidth
Custom Pydantic models for serializing and deserializing fixed-width format data.
🚀 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_fixedwidth-0.3.0.tar.gz.
File metadata
- Download URL: pydantic_fixedwidth-0.3.0.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc77eda038160a1ad6ad8bcc0836b39cad1098d0e1eb7421f6b179b4a819bbd6
|
|
| MD5 |
bf1b41fbb7c0405588af3054f0aec061
|
|
| BLAKE2b-256 |
4847f50dc34aac50846d197cc70fd5f438211a4ebf0bcd99e2118a4c5eefeff3
|
Provenance
The following attestation bundles were made for pydantic_fixedwidth-0.3.0.tar.gz:
Publisher:
release.yaml on lasuillard-s/pydantic-fixedwidth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_fixedwidth-0.3.0.tar.gz -
Subject digest:
dc77eda038160a1ad6ad8bcc0836b39cad1098d0e1eb7421f6b179b4a819bbd6 - Sigstore transparency entry: 1243342764
- Sigstore integration time:
-
Permalink:
lasuillard-s/pydantic-fixedwidth@3c0f6f95a8c49f4183ae3ec8a0df6e9542ab7e64 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/lasuillard-s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@3c0f6f95a8c49f4183ae3ec8a0df6e9542ab7e64 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydantic_fixedwidth-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_fixedwidth-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be7fe2a1de302600b7c569d2acd22a6137e398f1d0b2afa4b50a7c849b609d0
|
|
| MD5 |
48a0b8ed529fc8b5495d25f31926f731
|
|
| BLAKE2b-256 |
e2743a2862fb0db504ef6eefe31fbf2e233d41a44e7b7c747f87eac5b3fbb5f8
|
Provenance
The following attestation bundles were made for pydantic_fixedwidth-0.3.0-py3-none-any.whl:
Publisher:
release.yaml on lasuillard-s/pydantic-fixedwidth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_fixedwidth-0.3.0-py3-none-any.whl -
Subject digest:
3be7fe2a1de302600b7c569d2acd22a6137e398f1d0b2afa4b50a7c849b609d0 - Sigstore transparency entry: 1243342783
- Sigstore integration time:
-
Permalink:
lasuillard-s/pydantic-fixedwidth@3c0f6f95a8c49f4183ae3ec8a0df6e9542ab7e64 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/lasuillard-s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@3c0f6f95a8c49f4183ae3ec8a0df6e9542ab7e64 -
Trigger Event:
release
-
Statement type: