Skip to main content

Nano ID

CircleCI

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.

Usage

Install Nano ID using pip:

pip install nanoid

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

Metadata

Release files for nanoid 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanoid 2.0.0
File Size Uploaded Provenance
nanoid-2.0.0.tar.gz 3.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nanoid 2.0.0
File Interpreter ABI Platform
nanoid-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / nanoid-2.0.0.tar.gz

Download URL nanoid-2.0.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5a80cad5e9c6e9ae3a41fa2fb34ae189f7cb420b2a5d8f82bd9d23466e4efa68
BLAKE2b-256 checksum
How to use checksums
b79d0250bf5935d88e214df469d35eccc0f6ff7e9db046fc8a9aeb4b2a192775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / nanoid-2.0.0-py3-none-any.whl

Download URL nanoid-2.0.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90aefa650e328cffb0893bbd4c236cfd44c48bc1f2d0b525ecc53c3187b653bb
BLAKE2b-256 checksum
How to use checksums
2e0d8630f13998638dc01e187fadd2e5c6d42d127d08aeb4943d231664d6e539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Security for nanoid 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page