nanoid
A tiny, secure, URL-friendly, unique string ID generator for Python
What it is and what it does
nanoid is a lightweight ID generator that produces cryptographically secure, URL-safe unique strings. It uses a larger alphabet (A-Za-z0-9_-) than UUID, reducing the default ID length from 36 to 21 characters while maintaining similar collision probability. The package offers both a secure default generator and a faster non-secure variant, and supports custom alphabets and lengths for tuning collision risk versus ID compactness.
The library has no external dependencies and installs as a pure Python wheel, making it simple to add to any project. It's designed for scenarios where you need short, web-safe identifiers—such as URL slugs, database record IDs, or session tokens—without the overhead of UUID's longer format.
Use it for:
- Generate short, unique identifiers for database records or API resources that need to appear in URLs
- Create session tokens or temporary identifiers for web applications where compactness matters
- Build URL slugs or short links that are collision-resistant and safe to embed in query strings
- Replace UUID in scenarios where the 21-character format is preferable to UUID's 36-character standard
- Generate non-sequential IDs for distributed systems where collision probability is tuned to your scale
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates cryptographically secure, URL-friendly unique IDs shorter than UUIDs using an alphabet of A-Za-z0-9_- with configurable size and custom alphabets.
Yes, if you need short, secure, URL-safe IDs. The package is lightweight, dependency-free, and actively maintained in its repository. The 2018 PyPI release date warrants verification that the version on PyPI matches your needs, but the active repository status and zero security vulnerabilities make it a solid choice for ID generation.
Install
nanoid on PyPI
pip
pip install nanoiduv
uv add nanoidpoetry
poetry add nanoidInstalling nanoid
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is active with recent commits, though the latest PyPI release is from 2018.
License in practice
MIT license is permissive and imposes no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install nanoid
from nanoid import generate
generate() # => NDzkGoTCdRcaRyt7GOepg
generate(size=10) # => "IRFa-VaY2b"
generate('1234567890abcdef', 10) # => "4f9zd13a42"
Verify before relying
- Whether the 2018 latest_release date reflects a genuine maintenance gap or if newer versions exist only in the repository
- Specific collision probability guarantees for the default 21-character ID length
- Performance characteristics compared to UUID generation
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 2,824 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,492,585/month — #1,902 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: nanoid-2.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
fastnanoidGenerates unique, URL-friendly string IDs using…
permissive · top 15,000 on PyPI
shortuuidGenerates concise, URL-safe unique identifiers…
permissive · top 1,000 on PyPI
cuid2Generates collision-resistant,…
permissive · top 15,000 on PyPI
sqidsSqids encodes numbers into short, unique,…
permissive · top 15,000 on PyPI
ulidGenerates ULIDs (Universally Unique…
permissive · top 15,000 on PyPI
timeflakeGenerates 128-bit, time-ordered, URL-safe…
permissive · top 15,000 on PyPI
ulid-pyGenerates and parses ULIDs (Universally Unique…
permissive · top 5,000 on PyPI
hashidsGenerates short, unique, non-sequential hashes…
permissive · top 5,000 on PyPI
py-machineidRetrieves the unique machine ID of a host…
permissive · top 5,000 on PyPI
uuidProvides UUID object creation and RFC…
unclear · top 5,000 on PyPI