A tiny, secure URL-friendly, and fast unique string ID generator for Python, written in Rust.
Project Links
Meta
Author: Oliver Lambson, Ochir Erkhembayar
Maintainer: Oliver Lambson
Requires Python: >=3.8
Classifiers
Intended Audience
- Developers
Programming Language
- Rust
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
Operating System
- OS Independent
License
- OSI Approved :: MIT License
Typing
- Typed
fastnanoid
fastnanoid is a tiny, secure URL-friendly, and fast unique string ID generator for Python, written in Rust.
It works as a drop in replacement for py-nanoid's generate()
:
- from nanoid import generate
+ from fastnanoid import generate
It's 2.8x faster than the original.
When not to use it
If you need the same amount of entropy as uuid, you may as well use uuid and base64url encode it:
import uuid
from fastnanoid import urlid_to_uuid, uuid_to_urlid
# say you have a uuid, maybe from your database:
id_ = uuid.uuid4() # type: uuid.UUID
# you can encoded it in base64url so it displays as a short string:
urlid = uuid_to_urlid(id_) # type: str
# and when you read it back in from the user, you can convert it back to a normal UUID:
decoded_urlid = urlid_to_uuid(urlid) # type: UUID
This is simpler than using a nanoid which is not compliant with any existing standards. If you already have a generated UUID (say from a database), this is much faster than generating a new nanoid. (If you don't have a UUID, generating one plus encoding it in base64url is about 50% slower than fastnanoid.)
* these are very simple helper functions, you can easily implement them yourself and save a dependency.
Contributing
# local env
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt
# build and use
maturin develop
python -c 'import fastnanoid; print(fastnanoid.generate())'
# test
cargo test
pytest
mypy
ruff check
ruff format --check
Credits
Inspired by py-nanoid
Jun 30, 2025
0.4.3
Jun 30, 2025
0.4.2
Aug 11, 2024
0.4.1
Aug 11, 2024
0.3.1
Aug 11, 2024
0.3.0
Jun 10, 2024
0.2.2
Jun 10, 2024
0.2.1
Jun 10, 2024
0.2.0
Jun 05, 2024
0.1.1
Jun 05, 2024
0.1.0
Wheel compatibility matrix
Files in release
No dependencies