Skip to main content

PyNanoID

Ruff uv PyPI - Python Version PyPI - Version Coverage Status CI

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.

[!NOTE] If Rust based implementation is not available, the pure-Python generator will be automatically used.

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

[!WARNING] Non-secure generator uses random.random internally. Hence it is not recommended for generating tokens or secrets.

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

PyNanoID 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynanoid-0.2.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pynanoid-0.2.0-cp310-abi3-win_amd64.whl (111.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

pynanoid-0.2.0-cp310-abi3-win32.whl (103.1 kB view details)

Uploaded CPython 3.10+Windows x86

pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl (277.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl (197.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl (188.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ x86-64

pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (178.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file pynanoid-0.2.0.tar.gz.

File metadata

  • Download URL: pynanoid-0.2.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynanoid-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9a2b973e1f55abd7a1ee05b81343e22f89f232402cceeca5ac83490af03d9cc
MD5 0eb86aebe90205e9fbdadc650c2d8afa
BLAKE2b-256 f7122309f6c4b45e41af604918a908af919dd124f16c3f40260d9ef2339868e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0.tar.gz:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pynanoid-0.2.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 111.0 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f0dbe0e2d63500a92b8802674b1678c60268bc26d8dbc8e0c42921cee50084f6
MD5 f477da2d85b4625308dc63ed35a41ee1
BLAKE2b-256 008c6763b16ee3ba3f7dd0f99585e4cd7ae07b1aabd263c8de1b1473a58435ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-win_amd64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: pynanoid-0.2.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 103.1 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 a1bf4d138d13f54edd554d8685dd3ea23bbbad6a95637504e76f27a111243d3b
MD5 4c9c641d6f5331241915b295def0c151
BLAKE2b-256 7c9ba44ecef276a60471ed953858c5fdcb787baa45099a442a36d6f34e54167b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-win32.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 443c2efd40aca714f473b5617478041728edbd803f23d478a8c0e77645b63328
MD5 131aa0558d88cdba0214ece3d0cbc528
BLAKE2b-256 93ab5a1bc6b0de2899ce7635692f5d972cbe23018669a27374c0842a278c3b96

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ead16c7d5e38c4992b0fc48861e2e0d82048173718fb620a4d6b8c6507810cc3
MD5 bb6166ba45ed17fd1cb2024ccce93511
BLAKE2b-256 c6d8037832beb203d199b8fdec1ae989b6fec0214c418e0a18494aafad389ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 08b34e23442020651dd24e96eaaf1630d97855afead73062a19ae1065c90fe11
MD5 ca062eec0c64942c132cc5ce6fe090da
BLAKE2b-256 b5c6a415b2bf17f4c749068e1a13e5470a82f2b865206962f3750b3eb2e5c8a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-macosx_11_0_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89aaf68ac696fc947d48e870861f75a31a40b47cf5063676b0162d3cfa76d127
MD5 17982bc3ea9b42f91dc6f8c2df0bf45b
BLAKE2b-256 95f47e1aa432748c63554dfb60c6ed9a1b9c015900bcdfb3364fb5f81aa36d53

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.2.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

7 files

0.1.1

18 files

0.1.0

18 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page