Skip to main content

Type handling and normalization for non-standard types like email, phone numbers, money, dates, etc. serializable and deserializable as JSON, JSON Schema, and Pydantic.

Project description

atypical

Custom types for things like phone numbers, emails, etc. with normalization, Pydantic handling and JSON Schema serialization

Examples

from atypical.email import Email
from atypical.money import Money
from atypical.phone import PhoneNumber
from atypical.url import NormalizedURL
from sartorial.schema import Schema


class MyModel(Schema):
    email: Email
    phone_number: PhoneNumber
    amount: Money
    website: NormalizedURL

import json
print(MyModel.model_json_schema())  # or MyModel.to_schema_dict()

# Output
'''
{
    "additionalProperties": true,
    "properties": {
        "email": {
            "format": "email",
            "type": "string"
        },
        "phone_number": {
            "format": "phone",
            "type": "string"
        },
        "amount": {
            "format": "money",
            "type": "string"
        },
        "website": {
            "format": "normalized-url",
            "type": "string"
        }
    },
    "required": [
        "email",
        "phone_number",
        "amount",
        "website"
    ],
    "title": "MyModel",
    "type": "object"
}
 '''

m = MyModel(email="foo.bar+baz@gmail",
            phone_number="1 (212) 555-6789",
            amount="$100",
            website="example.com")

print(m.model_dump_json(indent=4))  # or m.to_json()

# Output
'''
{
    "email": "foobar@gmail.com",
    "phone_number": "+12125556789",
    "amount": "$100.00",
    "website": "https://example.com/"
}
'''

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atypical-0.3.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

atypical-0.3.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file atypical-0.3.1.tar.gz.

File metadata

  • Download URL: atypical-0.3.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for atypical-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3b4c0e5997fb7389077b854317667e7db1a9582762865706f89911ff58995ea8
MD5 67d00562e889dd8d65884d88078454a4
BLAKE2b-256 58a4ee1a23880fc87c539534f2e21c87fd957ff85de58f2ea959cb82912b00e4

See more details on using hashes here.

File details

Details for the file atypical-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: atypical-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for atypical-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a521c113ec46fae3bab68178943a44ec03103a6b268a2f55e2318487ec2dcb05
MD5 629519d1d5234cf214dabed17922ca48
BLAKE2b-256 5ae08880983d331889bac86513a444b80daa6306efa50d94bc1bb215acfdf35b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page