A snowflake implementation in Python
Project description
Snakeflake
Snakeflake is a discrete nonserial ID generator like Snowflake and Sonyflake, implemented in Python.
"Discrete" and "nonserial" are real words. I promise.
Usage
>>> import datetime
>>> from snakeflake.snakeflake import SnakeflakeGenerator
>>> from snakeflake.config import SnakeflakeGeneratorConfig
>>>
>>> # Set the epoch to 5:30, 28 March 2010 and the machine ID to 283
>>> config = SnakeflakeGeneratorConfig(datetime.datetime(2010, 3, 28, 5, 30), 283)
>>> # Create the Snakeflake Generator
>>> sf = SnakeflakeGenerator(config)
>>> # Generate some Snakeflake IDs
>>> sf.next_id()
526063632593715483
>>> sf.next_id()
526063667423281435
>>> # Not specifying a Machine ID will generate one from your internal IP address
>>> config = SnakeflakeGeneratorConfig(datetime.datetime(2010, 3, 28, 5, 30), None)
>>> config.machine_id
1
Installation
Eh maybe later.
To do:
- Better Documentation
-
Add an icon - Add a better icon
- Accept a function as a parameter to get the current machine id
- Accept a function as a parameter to check the uniqueness of the machine id
- Async support (if I decide to do the above)
- Add tests(!!!)
- Add a snakeflake decoder
- Publish (🎉🎉🎉)
Contributing
Want to contribute to this project? Feel free to submit a PR!
License
This project is licensed under the Apache 2.0 license.
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
snakeflake-0.1.5.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for snakeflake-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10b52b229d57f4a1dd3fbb7064cfb33d8e8b8d63594f82a6af5fffe974a0cf6a |
|
MD5 | 369aae484d33d52283ca2f4b4664e1b5 |
|
BLAKE2b-256 | 72743c144de50e27e7045bfcec006fcaded6fa53876dc04c1a60df8a139defe9 |