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
SnowflakeIdfor Snowflake ID validation. SnowflakeGeneratorfor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_snowflake-0.1.3.tar.gz.
File metadata
- Download URL: pydantic_snowflake-0.1.3.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
583689981640424ae7ebe34ae74760a46b09c1e523b82c6d274e431a54419956
|
|
| MD5 |
971d84d82ca6f86d3a989a8098f8d547
|
|
| BLAKE2b-256 |
96e34964c825c187f49bfe36b70f31a500cf9c932e992bd7e813e58dad50b841
|
File details
Details for the file pydantic_snowflake-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pydantic_snowflake-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1059170b91fd8e9c47c31d1923cf3087988e529504aa0688635a8ebc19f1c43
|
|
| MD5 |
0a2015163dae97d7051860f4353af446
|
|
| BLAKE2b-256 |
3065a0c62c14494b2cd91cc8b6ab9be66a2089e1fc6bfdda834399d14d92876c
|