Skip to main content

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

Project description

PyNanoID

Ruff PDM PyPI - Python Version PyPI - Version Coveralls code coverage 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())

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))

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))

Non-secure generator is also available.

from pynanoid import non_secure_generate

print(non_secure_generate())

[!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())
print(non_secure_generate())

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:

$ pytest tests/benchmark.py --benchmark-histogram=assets/benchmark.svg

Credits

Project details


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.1.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distributions

pynanoid-0.1.0-pp310-pypy310_pp73-win_amd64.whl (106.6 kB view details)

Uploaded PyPy Windows x86-64

pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (192.4 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (196.3 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pynanoid-0.1.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl (171.6 kB view details)

Uploaded PyPy macOS 11.0+ ARM64

pynanoid-0.1.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (177.2 kB view details)

Uploaded PyPy macOS 10.15+ x86-64

pynanoid-0.1.0-pp39-pypy39_pp73-win_amd64.whl (108.0 kB view details)

Uploaded PyPy Windows x86-64

pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (193.4 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (197.2 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pynanoid-0.1.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl (172.6 kB view details)

Uploaded PyPy macOS 11.0+ ARM64

pynanoid-0.1.0-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (178.2 kB view details)

Uploaded PyPy macOS 10.15+ x86-64

pynanoid-0.1.0-cp39-abi3-win_amd64.whl (107.5 kB view details)

Uploaded CPython 3.9+ Windows x86-64

pynanoid-0.1.0-cp39-abi3-win32.whl (98.9 kB view details)

Uploaded CPython 3.9+ Windows x86

pynanoid-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl (255.3 kB view details)

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

pynanoid-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (193.2 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

pynanoid-0.1.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (197.1 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pynanoid-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (172.5 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

pynanoid-0.1.0-cp39-abi3-macosx_10_9_x86_64.whl (177.9 kB view details)

Uploaded CPython 3.9+ macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pynanoid-0.1.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pynanoid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10af8e8aea7d9394a959760157958dcd36924b9026a1d8706522925004fbdcaf
MD5 9b537eb106456ab5adbfa296326ccc7a
BLAKE2b-256 a24533c74651aa09292c4c7b4766efd3a4a49756c44ee3bf021d2718aa2273c0

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp310-pypy310_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp310-pypy310_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 ed04679c98caf7d6d0f51b01d50950513ee2ee09d98c0c5c496fc33d8244566e
MD5 00f7aa88223b0aa5bb3ba179c818ed72
BLAKE2b-256 64070ae883ef377b4a70558ca7c723da546b0e1148b27a6d429887a1f2bfb9af

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b2fe033c9d07dac5c413ea4ca79c6c19b31b1f8dbe934852b569cf8dbf157c3
MD5 3468f19722a9f9c3674bbf9a0b690ef9
BLAKE2b-256 345f82676bcc2d06eed344c772349abb80c181764f84d5cd25aa20d27d0bceb1

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4593939e94fd307a9b0591034ba6858a66a5202aa83c1bac8d74d6c0459d353d
MD5 013f39be2e644171d5c1dde4f2da639e
BLAKE2b-256 bf36c3339ac77f34a893d5a33d2db46d3803403cfec90e5adf39c3722c44d1d7

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a78e245d3448ae033cc8130e524f4ed6cf0f3ce42da26c3ba570178d37ced3d5
MD5 43a13b4fab489c76b602d0b34bc5957a
BLAKE2b-256 1f69a425f76cb6209ae33a99b9e1508288188a09b9314df9517e24e83fa00211

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b204ed848315d1e9a30b3c85a06e7cb3e2bb863049db2faed9be163ea218ad0d
MD5 7bb0754fe21772102f29184b7df46f28
BLAKE2b-256 7a0b20ff6a4d13c335830482dcb23b13390547bb009084c3a387f1b1ce5d9bc6

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp39-pypy39_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 785b4b2863a28aa55c2daae7a6608fe98b83603e7b595be49dbdf16b2d8cb97d
MD5 5500ca7c5ed157ed4dd376a879663d0c
BLAKE2b-256 d5ad33596596c2ee185c3ba4e7787b03745ffcfd748daaca6202e7bfffd5220a

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b05b341233fb1338903af354b2cf0c6561c96a04041cd61207427dfa8711495c
MD5 cf38117a61d2145db317a6f4d518438a
BLAKE2b-256 81850a8ff309102254dd34da94c8d4562e49911c39c4ac17b383f30e6399d63a

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4f19a2d137b148cb19c1bd31a2575a574d010997419639926b4b3c81f24f9b31
MD5 e26be0aebacb6c218b4976b83f545cc1
BLAKE2b-256 00bcc958cb8c2334be65ee9aa897d470a6e81c8fdb30b6ad64b2a17e4cc6b7c2

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bd346b6b8a71dea899567d99183d3d36c1aa859f2e376499e114a5348859615d
MD5 6c8b753b1117cd10823370121d21703e
BLAKE2b-256 4cf6c0893ff72eeb7b3b31bf513c2d325995ba54ffdd48ae4d4d50e2aecaaf2c

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-pp39-pypy39_pp73-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7e2078f7b068f75f1cf60b68e4f39718a933c070786359b911334bf7045e8348
MD5 7fa28c562989c0baf89efef29b9b1e52
BLAKE2b-256 02725600a092023c6e2eb1bce2b3665352d8889c6a6537631a7ae78eaa8e33fd

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pynanoid-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 107.5 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9921536a6d334be17300534b81a4e4e40dfdac6a7bac05dc069e4ffe7f8039f5
MD5 865ae63d63225cf8779855d94ece085c
BLAKE2b-256 3d8f3e0fb9a263c20e0a48031bf29237c325dec30f1f88df591c4ec872c897e7

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-win32.whl.

File metadata

  • Download URL: pynanoid-0.1.0-cp39-abi3-win32.whl
  • Upload date:
  • Size: 98.9 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 dc830dedb2bcdc11e5982966ad3c2b7a2d902acb45840b9dc31a0c2ae38c9a5b
MD5 15f19b0c492373823a6988e7db34d949
BLAKE2b-256 0300cd49043379d87015174adf3843caca2cecd5f4f5603b1f869d3d3f82739d

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8782ed399231fd732c1f81629e37b5684daed2c9987559d30b08d1e27fc01dd9
MD5 670a1ae020d59edeb6d93a16164810c5
BLAKE2b-256 0ab1a749bd7f833d65e3539611d7d82ead60878c5b752aa0172c12df8c97e862

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8b1cadb75d494759b14a76539fa9006ccac57851f1a4c2bcd9ef9da37a52106
MD5 f2fa6052c278b0c2261b20d3f7f25b22
BLAKE2b-256 37735a697f90747c8891f2ced102f763d3f2c5823bee942ec4a5391e738da65b

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cbefa148a85a03ff92fe4b6a859dc7dabae44baa26aee5b566356cfd4a2cc713
MD5 bc85b821318662ca54c8aef4b6d88ce0
BLAKE2b-256 e06838957a476f1b3ab8eded815f49bd5ddb37175d0669c46f4eeb178a1f176e

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9ff5f4bec4e1229cdaed41b4af2824d305da85c7e19e8c09cdfc07067e04a5f
MD5 a2a6374baf7d327fcadf81cd64c95908
BLAKE2b-256 d29aae985047b8fcc16ffc7abb95b0e4cebeabbee2121fcd575eb780ea2aeea1

See more details on using hashes here.

File details

Details for the file pynanoid-0.1.0-cp39-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pynanoid-0.1.0-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 53dac83d960a596762d79f981d3e0eda11c8f32bf7d4cb9d4fe423bae98cbcda
MD5 5383960c5f855f6fd0087cc94b52b15c
BLAKE2b-256 c720af37e629136095f5fdcaa0baf4d4b66d12ca3810bcabdd6d59774790d05d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page