Nano ID

2.0.0 · active · verified Thu Apr 09

Nano ID is a tiny, secure, URL-friendly, unique string ID generator for Python. It provides compact IDs that are safer and shorter than UUIDs by using a larger alphabet and cryptographically strong random APIs. The current stable version is 2.0.0, and it is actively maintained.

Warnings

Install

Imports

Quickstart

Quickly generate secure, URL-friendly unique IDs. You can specify the length and a custom alphabet. A faster, non-secure generator is also available for less sensitive use cases.

from nanoid import generate, non_secure_generate

# Generate a default 21-character, URL-friendly ID
id_default = generate()
print(f"Default ID: {id_default}")

# Generate an ID with a specified length
id_short = generate(size=10)
print(f"Short ID (10 chars): {id_short}")

# Generate an ID with a custom alphabet and length
id_custom = generate('1234567890abcdef', 16)
print(f"Custom Alphabet ID: {id_custom}")

# Generate a non-secure ID (faster, but not for sensitive use)
id_non_secure = non_secure_generate()
print(f"Non-Secure ID: {id_non_secure}")

view raw JSON →