Skip to main content

A tiny, secure, URL-friendly, unique string ID generator for Python

Project description

Nano ID

A tiny, secure, URL-friendly, unique string ID generator for Python.

  • Safe. It uses cryptographically strong random APIs and tests distribution of symbols.
  • Compact. It uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.

Installation

pip install python-nanoid

Usage

Normal

The main module uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters (to have a collision probability similar to UUID v4).

from nanoid import generate

generate() # => NDzkGoTCdRcaRyt7GOepg

Symbols -,.() are not encoded in the URL. If used at the end of a link they could be identified as a punctuation symbol.

If you want to reduce ID length (and increase collisions probability), you can pass the length as an argument.

from nanoid import generate

generate(size=10) # => "IRFa-VaY2b"

Don’t forget to check the safety of your ID length in ID collision probability calculator.

Custom Alphabet or Length

If you want to change the ID's alphabet or length you can use the internal generate module.

from nanoid import generate

generate('1234567890abcdef', 10) # => "4f9zd13a42"

Non-secure API is also available:

from nanoid import non_secure_generate

non_secure_generate('1234567890abcdef', 10)

Tools

  • ID size calculator to choice smaller ID size depends on your case. nanoid-dictionary with popular alphabets to use with nanoid/generate.
  • nanoid-dictionary with popular alphabets to use.

Other Programming Languages

Changelog

  • v2.0.0
    • Replace ~ to - in default alphabet.
    • Add non-secure fast generator.
    • Reduce default characters from 22 to 21.
  • v0.3.0
    • Fix array out of bound error.

Credits

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

python_nanoid-2.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

python_nanoid-2.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file python_nanoid-2.0.0.tar.gz.

File metadata

  • Download URL: python_nanoid-2.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for python_nanoid-2.0.0.tar.gz
Algorithm Hash digest
SHA256 585b6e5ed5ad00433027e8164aea673dfbdc7ae22603f042b0466b1f7543ddeb
MD5 0cf85bf9166659a615c9bc43d08b3d3a
BLAKE2b-256 a286d2eebedf861cc24e270a3b1ae6144155ac32a3e82cc157211f26d8be5e4b

See more details on using hashes here.

File details

Details for the file python_nanoid-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_nanoid-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fea83f148f2e9c90fa0d8757b8a99afa1f3e452c71c2ea07ed8f1b93e641a97d
MD5 8af2d1b3afd540a9c3e87d70e81659eb
BLAKE2b-256 7c493ab474eb20ba43424621d1875291a542dc607e30f36d15d2b69473fd7389

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