skillfed

nanoid

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

nanoid v2.0.0 6.5M downloads/30d#1,902 on PyPI512
Permissive license MIT Active released

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 nanoid

uv

uv add nanoid

poetry

poetry add nanoid

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonTopic :: Utilities

Tags

unique id generatorsecure random idurl-friendly idnano id pythonuuid alternativeshort unique stringcollision-resistant id
id-generationcryptographyurl-safe

More Utilities packages