Giter Site home page Giter Site logo

akhundmurad / typeid-python Goto Github PK

View Code? Open in Web Editor NEW
77.0 1.0 6.0 70 KB

Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs

License: MIT License

Makefile 3.48% Python 96.52%
base32 cryptography encryption guid identity python typeid uuid uuid7

typeid-python's Introduction

Hi ๐Ÿ‘‹, I'm Murad

A backend developer from Baku

๐ŸŒ Socials:

LinkedIn

๐Ÿ’ป Tech Stack:

Python Google Cloud DigitalOcean Firebase FastAPI DjangoREST Django MongoDB Redis Postgres SQLite Postman Docker Swagger Jira

๐Ÿ“Š GitHub Stats:



โœ๏ธ Random Dev Quote

typeid-python's People

Contributors

akhundmurad avatar beheh avatar oselz avatar rustam24052003 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

typeid-python's Issues

Inconsistencies in TypeID class

Hi, and thanks for this package!

I noticed a couple of inconsistencies in the TypeID class:

@classmethod
def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
    suffix_str = _convert_uuid_to_b32(suffix)
    return TypeID(suffix=suffix_str, prefix=prefix)

this class method explicitly returns a TypeID, when it could use cls, like the from_string method right above it.

def _convert_b32_to_uuid(b32: str) -> UUID:
    return UUID(bytes=bytes(base32.decode(b32)))

I think this utility function should return the customized uuid6.UUID instead of uuid.UUID, since the class constructor calls uuid6.uuid7(). The difference is subtle, but this way the .uuid property can return incorrect results if you try to access .uuid.time:

uuid = uuid6.uuid7()
print(uuid.time)
>>> 1712728754957

tid = typeid.TypeID()
print(tid.uuid.time)
>>> 688659269629691542

uuid6.UUID has an overridden time property, which checks the version, and returns super().time if the version is not 6, 7, or 8.

The utility function could be updated like so:

def _convert_b32_to_uuid(b32: str):
    uuid_bytes = bytes(base32.decode(b32))
    uuid_int = int.from_bytes(uuid_bytes)
    return uuid6.UUID(int=uuid_int, version=7)

I ran into this while playing around with the idea of modifying the uuid6.uuid7 generator function to receive the timestamp part as a parameter, so that I could also create TypeID instances based on some historical timestamp. This'd be a really useful feature when migrating from database-generated sequenced numeric IDs to TypeIDs. Some other ID generation libraries support this.

I can open a PR for these changes if you'd like. Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.