Code Monkey home page Code Monkey logo

uuid-utils's Introduction

Python UUID Utils

Package version Supported Python versions


Python UUID implementation using Rust's UUID library. This will make uuid4 function around 10x faster.

This package can be a drop-in replacement to the standard library UUID which implements existing UUID versions like V4 in Rust and also adds draft UUID versions like V6.

Avaialble UUID versions:

  • uuid1 - Version 1 UUIDs using a timestamp and monotonic counter.
  • uuid3 - Version 3 UUIDs based on the MD5 hash of some data.
  • uuid4 - Version 4 UUIDs with random data.
  • uuid5 - Version 5 UUIDs based on the SHA1 hash of some data.
  • uuid6 - Version 6 UUIDs using a timestamp and monotonic counter.
  • uuid7 - Version 7 UUIDs using a Unix timestamp ordered by time.
  • uuid8 - Version 8 UUIDs using user-defined data.

Please note that UUID versions 6, 7 and 8 are still in draft RFC.

Installation

Using pip:

$ pip install uuid-utils

or, using conda:

$ conda install -c conda-forge uuid-utils

Example

>>> import uuid_utils as uuid

>>> # make a random UUID
>>> uuid.uuid4()
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')

>>> # make a random UUID using a Unix timestamp which is time-ordered.
>>> uuid.uuid7()
UUID('018afa4a-0d21-7e6c-b857-012bc678552b')

>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')

>>> # make a UUID using an MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')

Compat module

In some cases you might need UUID instances to be returned from the standrad-library uuid, not a custom UUID class. In that case you can use the uuid_utils.compat which comes with a performance penalty in comparison with the uuid_utils default behaviour, but still faster than the standard-library.

>>> import uuid_utils.compat as uuid

>>> # make a random UUID
>>> uuid.uuid4()
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')

Benchmarks

Benchmark Min Max Mean Min (+) Max (+) Mean (+)
UUID V1 0.058 0.059 0.058 0.005 (12.0x) 0.005 (11.9x) 0.005 (12.0x)
UUID V3 0.063 0.064 0.063 0.008 (7.9x) 0.008 (8.1x) 0.008 (8.0x)
UUID V4 0.041 0.041 0.041 0.004 (11.1x) 0.004 (10.8x) 0.004 (10.9x)
UUID V5 0.064 0.066 0.065 0.008 (8.1x) 0.008 (8.1x) 0.008 (8.1x)
UUID from hex 0.024 0.025 0.024 0.004 (6.7x) 0.004 (6.6x) 0.004 (6.6x)
UUID from bytes 0.024 0.025 0.024 0.004 (6.7x) 0.004 (6.6x) 0.004 (6.7x)
UUID from int 0.024 0.025 0.024 0.004 (6.6x) 0.004 (6.7x) 0.004 (6.6x)
UUID from fields 0.028 0.028 0.028 0.009 (3.1x) 0.009 (3.1x) 0.009 (3.1x)

How to develop locally

$ make build
$ make test

Or:

$ RUSTFLAGS="--cfg uuid_unstable" maturin develop --release

uuid-utils's People

Contributors

aminalaee avatar alanhamlett avatar angelsenra avatar moritzwilksch avatar lepenkinya avatar zer0x00 avatar

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.