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-snowflake

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.2.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.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_snowflake-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 249ac2de0ca278483dbf89ef4cf6c20f4c6db6243045c6311d06b7b3112af6a1
MD5 661a9be8a70693cffc44cbee180fe4dc
BLAKE2b-256 414082ef383c7a7a0f784716c0dd44d4d2d7ab65ba3c0be366397c4c45384bd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_snowflake-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e4fa042281e486c5a9f1a490ff1fd2a6ffd7d272608f2689db6a4e8b091d3a
MD5 8e3f3c05e43e2f881b70a3ac7a343e43
BLAKE2b-256 1286de096e5b39ee9cf6d5d84aac98a3c78030bed9a87ccd30759cf354b0e53a

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