grammarie


Namegrammarie JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://gitlab.statnett.no//grammarie.git
SummaryCustom Pydantic types and validators
upload_time2024-06-14 07:30:47
maintainerNone
docs_urlNone
authorStatnett Datascience
requires_python<4.0,>=3.10
licenseNone
keywords pydantic types validation coercion annotated
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # grammarie

Grammarie is a type of [Fae magic](https://kingkiller.fandom.com/wiki/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.

```python
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](https://python-poetry.org/) to manage the environment and Python dependencies.
To install the development environment and run the test suite:
```bash
poetry install
poetry run pytest
```

It's recommended to also install the pre-commit hooks:
```bash
poetry run pre-commit install
```

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


            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.statnett.no//grammarie.git",
    "name": "grammarie",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "pydantic, types, validation, coercion, annotated",
    "author": "Statnett Datascience",
    "author_email": "Datascience.Drift@Statnett.no",
    "download_url": "https://files.pythonhosted.org/packages/b0/15/fcb74cd4c3eaf77a1629698cb20980da559218b7e8f61dd5df79c9ee3b82/grammarie-0.1.1.tar.gz",
    "platform": null,
    "description": "# grammarie\n\nGrammarie is a type of [Fae magic](https://kingkiller.fandom.com/wiki/Fae_magic) that is the craft\nof making things be. This package helps you shape your data into its proper form.\n\nMore specifically, this package defines a set of types annotated in a way that let's Pydantic validate and/or coerce\ndata into the target type and form.\n\nIn the example below, data is provided with wrong types and formats, but are coerced by the types defined by the model\nand its fields.\n\n```python\nfrom datetime import UTC, datetime\nfrom pydantic import BaseModel\nfrom grammarie import Decimal1, IntTimestampMS, LowercaseStr, UppercaseStr\n\n\nclass PowerTransformer(BaseModel):\n    id: LowercaseStr\n    name: UppercaseStr\n    voltage_primary: Decimal1\n    voltage_secondary: Decimal1\n    installation_date: IntTimestampMS\n\n\ntransformers = [\n    PowerTransformer(\n        id=\"d37dca6f-6f23-4401-8cc8-e3ee422939e4\",\n        name=\"S Ulven T1 Transformator\",\n        voltage_primary=420.00056,\n        voltage_secondary=\"132\",\n        installation_date=\"2023-05-03 11:15:01\",\n    ),\n    PowerTransformer(\n        id=\"26381360-959A-4D39-8049-D20889FAE0d6\",\n        name=\"S Ofoten T2 Transformator\",\n        voltage_primary=\"420\",\n        voltage_secondary=300,\n        installation_date=datetime(2021, 8, 16, 8, 35, 1, tzinfo=UTC),\n    ),\n]\n\nprint(transformers)\n# [\n#     PowerTransformer(\n#         id='d37dca6f-6f23-4401-8cc8-e3ee422939e4',\n#         name='S ULVEN T1 TRANSFORMATOR',\n#         voltage_primary=Decimal('420.0'),\n#         voltage_secondary=Decimal('132.0'),\n#         installation_date=1683105301000\n#     ),\n#     PowerTransformer(\n#         id='26381360-959a-4d39-8049-d20889fae0d6',\n#         name='S OFOTEN T2 TRANSFORMATOR',\n#         voltage_primary=Decimal('420.0'),\n#         voltage_secondary=Decimal('300.0'),\n#         installation_date=1629102901000\n#     )\n# ]\n```\n\n## Installation\n\nThis package is available on PyPI and can be installed with pip, uv, pdm, poetry or any other package manager.\n\n## Development\n\nThis project uses [Poetry](https://python-poetry.org/) to manage the environment and Python dependencies.\nTo install the development environment and run the test suite:\n```bash\npoetry install\npoetry run pytest\n```\n\nIt's recommended to also install the pre-commit hooks:\n```bash\npoetry run pre-commit install\n```\n\nThis ensures that linting and formatting are run automatically on every commit.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Custom Pydantic types and validators",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://gitlab.statnett.no//grammarie.git",
        "Repository": "https://gitlab.statnett.no//grammarie.git"
    },
    "split_keywords": [
        "pydantic",
        " types",
        " validation",
        " coercion",
        " annotated"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e42187f2bd02400b04d4901ba854e67d63380b13993cd4a6f85bfb3a3fda379",
                "md5": "7302840cec7f6f7994d4019287a02429",
                "sha256": "240f8c3d21153487bdf6270f5dcba1216c8298f2226826a47c28ea24559a3f05"
            },
            "downloads": -1,
            "filename": "grammarie-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7302840cec7f6f7994d4019287a02429",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 4576,
            "upload_time": "2024-06-14T07:30:46",
            "upload_time_iso_8601": "2024-06-14T07:30:46.314202Z",
            "url": "https://files.pythonhosted.org/packages/5e/42/187f2bd02400b04d4901ba854e67d63380b13993cd4a6f85bfb3a3fda379/grammarie-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b015fcb74cd4c3eaf77a1629698cb20980da559218b7e8f61dd5df79c9ee3b82",
                "md5": "f173e2fb8957bfe339fe9c139fffcd12",
                "sha256": "7ad5d35bd5c1eaadbb8b372deccedd1bc047e1f418975d8473ee37e644c3feae"
            },
            "downloads": -1,
            "filename": "grammarie-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f173e2fb8957bfe339fe9c139fffcd12",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5229,
            "upload_time": "2024-06-14T07:30:47",
            "upload_time_iso_8601": "2024-06-14T07:30:47.404063Z",
            "url": "https://files.pythonhosted.org/packages/b0/15/fcb74cd4c3eaf77a1629698cb20980da559218b7e8f61dd5df79c9ee3b82/grammarie-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-14 07:30:47",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "grammarie"
}
        
Elapsed time: 0.63473s