Skip to main content

grammarie

Grammarie is a type of Fae magic that is the craft of making things be. This package helps you shape your data into its proper form.

More specifically, this package defines a set of types annotated in a way that let's Pydantic validate and/or coerce data into the target type and form.

In the example below, data is provided with wrong types and formats, but are coerced by the types defined by the model and its fields.

from datetime import UTC, datetime
from pydantic import BaseModel
from grammarie import Decimal1, IntTimestampMS, LowercaseStr, UppercaseStr


class PowerTransformer(BaseModel):
    id: LowercaseStr
    name: UppercaseStr
    voltage_primary: Decimal1
    voltage_secondary: Decimal1
    installation_date: IntTimestampMS


transformers = [
    PowerTransformer(
        id="d37dca6f-6f23-4401-8cc8-e3ee422939e4",
        name="S Ulven T1 Transformator",
        voltage_primary=420.00056,
        voltage_secondary="132",
        installation_date="2023-05-03 11:15:01",
    ),
    PowerTransformer(
        id="26381360-959A-4D39-8049-D20889FAE0d6",
        name="S Ofoten T2 Transformator",
        voltage_primary="420",
        voltage_secondary=300,
        installation_date=datetime(2021, 8, 16, 8, 35, 1, tzinfo=UTC),
    ),
]

print(transformers)
# [
#     PowerTransformer(
#         id='d37dca6f-6f23-4401-8cc8-e3ee422939e4',
#         name='S ULVEN T1 TRANSFORMATOR',
#         voltage_primary=Decimal('420.0'),
#         voltage_secondary=Decimal('132.0'),
#         installation_date=1683105301000
#     ),
#     PowerTransformer(
#         id='26381360-959a-4d39-8049-d20889fae0d6',
#         name='S OFOTEN T2 TRANSFORMATOR',
#         voltage_primary=Decimal('420.0'),
#         voltage_secondary=Decimal('300.0'),
#         installation_date=1629102901000
#     )
# ]

Installation

This package is available on PyPI and can be installed with pip, uv, pdm, poetry or any other package manager.

Development

This project uses Poetry to manage the environment and Python dependencies. To install the development environment and run the test suite:

poetry install
poetry run pytest

It's recommended to also install the pre-commit hooks:

poetry run pre-commit install

This ensures that linting and formatting are run automatically on every commit.

Metadata

Release files for grammarie 0.1.1

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

Source distribution (sdist)

Source distribution for grammarie 0.1.1
File Size Uploaded
grammarie-0.1.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grammarie 0.1.1
File Interpreter ABI Platform
grammarie-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / grammarie-0.1.1.tar.gz

Download URL grammarie-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7ad5d35bd5c1eaadbb8b372deccedd1bc047e1f418975d8473ee37e644c3feae
BLAKE2b-256 checksum
How to use checksums
b015fcb74cd4c3eaf77a1629698cb20980da559218b7e8f61dd5df79c9ee3b82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / grammarie-0.1.1-py3-none-any.whl

Download URL grammarie-0.1.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
240f8c3d21153487bdf6270f5dcba1216c8298f2226826a47c28ea24559a3f05
BLAKE2b-256 checksum
How to use checksums
5e42187f2bd02400b04d4901ba854e67d63380b13993cd4a6f85bfb3a3fda379
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.0.1

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