Skip to main content

A Pydantic custom type for handling Snowflake IDs with ease.

Project description

Pydantic Snowflake ID

A Pydantic custom type for validating and serializing Snowflake IDs.

Features

  • Custom Pydantic type SnowflakeId for Snowflake ID validation.
  • SnowflakeGenerator for generating unique Snowflake IDs.
  • Supports custom epochs, worker IDs, and process IDs.
  • Supports serialization and deserialization of pydantic models with Snowflake IDs.

Installation

You can install the package via pip:

pip install -U pydantic-snowflakes

Usage

from pydantic import BaseModel
from pydantic_snowflake import SnowflakeId, SnowflakeGenerator

from datetime import datetime

custom_epoch = datetime(2020, 1, 1)

class User(BaseModel):
    id: SnowflakeId
    name: str

# Generating a Snowflake ID
generator = SnowflakeGenerator(
    epoch=custom_epoch,
    worker_id=0,
    process_id=0
)

new_id = generator.next()
user = User(id=new_id, name="Alice")
print(user)

# Generating multiple Snowflake IDs
for _id in [generator.next() for _ in range(5)]:
    user = User(id=_id, name="Bob")
    print(user)

License

MIT License

Copyright (c) 2025-2026, Chih-Hao Chuang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

pydantic_snowflake-0.1.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_snowflake-0.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_snowflake-0.1.1.tar.gz.

File metadata

  • Download URL: pydantic_snowflake-0.1.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pydantic_snowflake-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e44db7192b717ca5bf367d1d52728a1b0a02df3e9a927375408d52dc79ccc045
MD5 d99c3b20056f87deda5cd38280761e49
BLAKE2b-256 1c374fbb1f4da35db6b1599481934ad7f15fb71836ce7cd0a56fcc63299494aa

See more details on using hashes here.

File details

Details for the file pydantic_snowflake-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_snowflake-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b235b009338af3a35224fe23e9a06081eda0bef4c82e339c43a7a706aeda1d2
MD5 6ec2fb741b4ca2969ddcfafaa97399a4
BLAKE2b-256 7bcd72078610691a256c70d1ad7d7042cbe2d2c8bc5ca273a0912418b2fcc6ca

See more details on using hashes here.

Supported by

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