PyNanoID
A tiny, secure, URL-friendly, unique string ID generator for Python, written in Rust.
- Safe. It uses hardware random generator. Can be used in clusters.
- Fast. 2-3 times faster than Python based generator.
- Compact. It uses a larger alphabet than UUID (
A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.
Installation
pip install pynanoid
Usage
from pynanoid import generate
print(generate())
# SxuPyeUFRnoWnNlwtLBvT
Symbols -,.() are not encoded in the URL. If used at the end of a link they
could be identified as a punctuation symbol.
The Rust based high-performance generator is used by default if available. You can also use pure-Python based generator as shown here.
If you want to reduce ID length (and increase the probability of collisions), you can pass the length as an argument.
from pynanoid import generate
print(generate(size=10))
# WtYW30_vPi
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 pass the alphabet as the first argument and the size as the second argument.
from pynanoid import generate
print(generate("1234567890abcdef", 10))
# bced90bd56
Non-secure generator is also available.
from pynanoid import non_secure_generate
print(non_secure_generate())
# JlJp1Od7zjlcrfIttk0JB
Force Use Pure-Python Generator
If you want to use the pure-Python generator, you can use functions provided in
pynanoid.nanoid.
from pynanoid.nanoid import generate, non_secure_generate
print(generate()) # wBM-LJLoliqnGTOf38Qf4
print(non_secure_generate()) # ekN1GQBxPNjKM3XFGVO8q
Benchmarks
We benchmark using
pytest-benchmark. You can
find the benchmark script in the tests/ directory.
You can run the benchmarks using the following command:
uv run pytest tests/benchmark.py --benchmark-histogram=assets/benchmark
Development
This project uses uv for Python packaging and maturin to build the Rust extension. You will also need a Rust toolchain.
# Create the virtual environment and build the extension.
uv sync
# Run the Python test suite.
uv run pytest
# Lint, format, and type-check.
uv run ruff check .
uv run ruff format .
uv run mypy .
# Rust checks.
cargo test
cargo clippy --all-targets --all-features
cargo fmt --all
# Rebuild the extension after changing Rust code.
uv run maturin develop
Credits
Metadata
Release files for pynanoid 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pynanoid-0.2.0.tar.gz | 12.2 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pynanoid-0.2.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| pynanoid-0.2.0-cp310-abi3-win32.whl | CPython 3.10 | abi3 | Windows x86-32 | Details |
| pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl | CPython 3.10 | abi3 | macOS 11.0+ x86-64 | Details |
| pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 1.1 MB
Release files / pynanoid-0.2.0.tar.gz
| Download URL | pynanoid-0.2.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9a2b973e1f55abd7a1ee05b81343e22f89f232402cceeca5ac83490af03d9cc
|
|
BLAKE2b-256 checksum How to use checksums |
f7122309f6c4b45e41af604918a908af919dd124f16c3f40260d9ef2339868e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-win_amd64.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 111.0 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f0dbe0e2d63500a92b8802674b1678c60268bc26d8dbc8e0c42921cee50084f6
|
|
BLAKE2b-256 checksum How to use checksums |
008c6763b16ee3ba3f7dd0f99585e4cd7ae07b1aabd263c8de1b1473a58435ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-win32.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-win32.whl |
|---|---|
| Size | 103.1 kB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
a1bf4d138d13f54edd554d8685dd3ea23bbbad6a95637504e76f27a111243d3b
|
|
BLAKE2b-256 checksum How to use checksums |
7c9ba44ecef276a60471ed953858c5fdcb787baa45099a442a36d6f34e54167b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 277.7 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
443c2efd40aca714f473b5617478041728edbd803f23d478a8c0e77645b63328
|
|
BLAKE2b-256 checksum How to use checksums |
93ab5a1bc6b0de2899ce7635692f5d972cbe23018669a27374c0842a278c3b96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 197.2 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ead16c7d5e38c4992b0fc48861e2e0d82048173718fb620a4d6b8c6507810cc3
|
|
BLAKE2b-256 checksum How to use checksums |
c6d8037832beb203d199b8fdec1ae989b6fec0214c418e0a18494aafad389ebd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 188.3 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
08b34e23442020651dd24e96eaaf1630d97855afead73062a19ae1065c90fe11
|
|
BLAKE2b-256 checksum How to use checksums |
b5c6a415b2bf17f4c749068e1a13e5470a82f2b865206962f3750b3eb2e5c8a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency logRelease files / pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 178.8 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
89aaf68ac696fc947d48e870861f75a31a40b47cf5063676b0162d3cfa76d127
|
|
BLAKE2b-256 checksum How to use checksums |
95f47e1aa432748c63554dfb60c6ed9a1b9c015900bcdfb3364fb5f81aa36d53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.
Transparency log