Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typeid-python

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeid-python

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

  • 0.3.1
  • PyPI
  • Socket score

Maintainers
1

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
    

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc