Skip to main content

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

Project description

TypeID Python

Test Downloads Package version Supported Python versions

A Python implementation of TypeIDs using Python

TypeIDs are a modern, type-safe, globally unique identifier based on the upcoming UUIDv7 standard. They provide a ton of nice properties that make them a great choice as the primary identifiers for your data in a database, APIs, and distributed systems. Read more about TypeIDs in their spec.

This particular implementation provides an pip package that can be used by any Python project.

Installation

  • PyPI:

    pip install typeid-python
    
  • Poetry:

    poetry add typeid-python
    

Usage

Basic

  • Create TypeID Instance:

    from typeid import TypeID
    
    typeid = TypeID()
    
    print(typeid.prefix)  # ""
    print(typeid.suffix)  # "01h45ytscbebyvny4gc8cr8ma2" (encoded uuid7 instance)
    
    typeid = TypeID(prefix="user")
    
    print(typeid.prefix)  # "user"
    print(str(typeid))  # "user_01h45ytscbebyvny4gc8cr8ma2"
    
  • Create TypeID from string:

    from typeid import TypeID
    
    typeid = TypeID.from_string("user_01h45ytscbebyvny4gc8cr8ma2")
    
    print(str(typeid))  # "user_01h45ytscbebyvny4gc8cr8ma2"
    
  • Create TypeID from uuid7:

    from typeid import TypeID
    from uuid6 import uuid7
    
    uuid = uuid7()  # UUID('01890bf0-846f-7762-8605-5a3abb40e0e5')
    prefix = "user"
    
    typeid = TypeID.from_uuid(prefix=prefix, suffix=uuid)
    
    print(str(typeid))  # "user_01h45z113fexh8c1at7axm1r75"
    

CLI-tool

  • Install dependencies:

    pip install typeid-python[cli]
    
  • To generate a new TypeID, run:

    $ python3 -m typeid.cli new -p prefix
    prefix_01h2xcejqtf2nbrexx3vqjhp41
    
  • To decode an existing TypeID into a UUID run:

    $ python3 -m typeid.cli decode prefix_01h2xcejqtf2nbrexx3vqjhp41
    type: prefix
    uuid: 0188bac7-4afa-78aa-bc3b-bd1eef28d881
    
  • And to encode an existing UUID into a TypeID run:

    $ python3 -m typeid.cli encode 0188bac7-4afa-78aa-bc3b-bd1eef28d881 --prefix prefix
    prefix_01h2xcejqtf2nbrexx3vqjhp41
    

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

typeid_python-0.3.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

typeid_python-0.3.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file typeid_python-0.3.1.tar.gz.

File metadata

  • Download URL: typeid_python-0.3.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for typeid_python-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f96a78c5dc6d8df1d058b72598bcc2c1c5bb8d8343f53f910e074dae01458417
MD5 0c137d7dc7aeced99b2c7f7fce02d9e8
BLAKE2b-256 25c34d4cfcdc4a568e50b0f4702fafac66e01934ded5efc4f822ed4d38d29780

See more details on using hashes here.

File details

Details for the file typeid_python-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for typeid_python-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62a6747933b3323d65f0bf91c8e8c7768b0292eaf9c176fb0c934ff3a61acce5
MD5 f7ea8d307edb459d6174a869b19cd4f4
BLAKE2b-256 f4a63929b4574b02541a07b3fd61f6d2757eb263dcf606ecfb71b63d504cfd08

See more details on using hashes here.

Supported by

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