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

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

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

Uploaded Source

Built Distributions

pynanoid-0.1.1-pp310-pypy310_pp73-win_amd64.whl (109.2 kB view details)

Uploaded PyPy Windows x86-64

pynanoid-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.2 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pynanoid-0.1.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (210.4 kB view details)

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

pynanoid-0.1.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl (180.6 kB view details)

Uploaded PyPy macOS 11.0+ ARM64

pynanoid-0.1.1-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (188.9 kB view details)

Uploaded PyPy macOS 10.15+ x86-64

pynanoid-0.1.1-pp39-pypy39_pp73-win_amd64.whl (110.4 kB view details)

Uploaded PyPy Windows x86-64

pynanoid-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (203.0 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pynanoid-0.1.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (210.9 kB view details)

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

pynanoid-0.1.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl (181.3 kB view details)

Uploaded PyPy macOS 11.0+ ARM64

pynanoid-0.1.1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (189.9 kB view details)

Uploaded PyPy macOS 10.15+ x86-64

pynanoid-0.1.1-cp39-abi3-win_amd64.whl (110.0 kB view details)

Uploaded CPython 3.9+ Windows x86-64

pynanoid-0.1.1-cp39-abi3-win32.whl (102.7 kB view details)

Uploaded CPython 3.9+ Windows x86

pynanoid-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl (264.8 kB view details)

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

pynanoid-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.5 kB view details)

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

pynanoid-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (210.6 kB view details)

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

pynanoid-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (181.1 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

pynanoid-0.1.1-cp39-abi3-macosx_10_9_x86_64.whl (189.5 kB view details)

Uploaded CPython 3.9+ macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pynanoid-0.1.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pynanoid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9c4c6cc5888a7071e7d308be3e65aeef891c0acd21ccfe943b74cdc3b2bdf43
MD5 a086bbda9728e7b9a5a313f80d2fd893
BLAKE2b-256 3e8b6ad706ee5f552b5648bfae6900ae3da0455c9e853b962543aa707609f5e2

See more details on using hashes here.

Provenance

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

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp310-pypy310_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 9fdb3ff98cf1da833d8c28887868eac3c7f67682065808974e6d4740dc0c686e
MD5 c7260a0b389c235cec856bd27d88263b
BLAKE2b-256 509bd58e8cc2da9673357e22f2ed91f7fbec0c92e7687662f313bb1ebac3c0be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp310-pypy310_pp73-win_amd64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8aa4caa9fe4ec03ac6656f8c8cb22b38f1ff07c3252be380bb073936d630ed7f
MD5 624c3910991c0a1a445dd5f4406c0722
BLAKE2b-256 c73e5cf4f2765cc92d38e5cb21e0d7534537f72d47610cc8cd2377864aaa327f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

Details for the file pynanoid-0.1.1-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.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d628b8154600e22267d0a4bb4bd5446bd23e7108434b4116384ee73848460f60
MD5 09c9b6ee80def74c27a0d0ee47d29de3
BLAKE2b-256 f685a96af460d66412a132da5917a39bd934e410dd043b49b163a1e4fcf41ec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 daba561022b1e68c9f2a8678641342467b9cf5e4d268af7a16a149928dfe7436
MD5 2a9cb3d0abfa63272d85467a5734a651
BLAKE2b-256 16287d2bf9bc29d3f2a963e8c0e86f8af9dd24e815538e115bd109dddb75b483

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp310-pypy310_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4143fe24aa25ad22a354b7ece9a67cce248ed7ccfe83a9e362ff4515889e84e9
MD5 2466fc357eb1dc2b9bae348f815f765f
BLAKE2b-256 3c03d29072de8d00ca80dd65c7456c06d1e9256f2a98e057b8b903c4490148fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp310-pypy310_pp73-macosx_10_15_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 7f6c6690b65a4a8aea4aa39f267df8857f0f1474ae6a3a811c010689f2029d76
MD5 072d80f663f528e75971ddc5f5181a33
BLAKE2b-256 c69a1a8210e98ffce2ea941524ba5e978b35a680f371eaedf3914c550a2b2242

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp39-pypy39_pp73-win_amd64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27cb1f415481fc8f120c40a3df25a47fbdcfcd149b1486ca2a475c3cf1fde727
MD5 dcac162ac737dde3004fa650781025f0
BLAKE2b-256 04a8cace51d9a456a97ef36f434c7f3dbfb02267f00f9baec81eacdf27008d4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

Details for the file pynanoid-0.1.1-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.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4d8d417550b6c6591ba2f302b6a1e45a18142fd012f0c975db5f3af410cbdaf8
MD5 04a7e3cdc6172dac89762dc0c2aac334
BLAKE2b-256 72031ebaaa297ac7571ed8b42da65b83bc0e2a47ca089dd4dfc9d7894999fc22

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f7e3713fd6a2171b521964a0ccc399aa11b68c35fe4c8639d104e9c4a14cc3f
MD5 4bd4d12fd7efa954c0326d8377472350
BLAKE2b-256 d7de9901946a4079a113e70c7215d2d99f1c1ec771b9d751c50aa875bf69b44f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 060f3ac3de446cd783be8342110ce29ab527c43a4aeeeb16f982c39fce8ffd9c
MD5 3e9c17823e6dd941ef92ad9015897338
BLAKE2b-256 107cf927d11f2d843a3ee256c8a70773f413c1cde720c324fbd17a5ed59f9ab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

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

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b55f5f9b2ace54a528e81f008310de995c7f17590c36251c6396a8590695dadd
MD5 4658065132e9bcbde229926602c9ae0b
BLAKE2b-256 72cc9c0ed14cdf9acc137e2bc89a9ac441db27f523cce26514069d764cb7321f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-win_amd64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

  • Download URL: pynanoid-0.1.1-cp39-abi3-win32.whl
  • Upload date:
  • Size: 102.7 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 b863bdfc1337b4c54ac43326fb8d6a65ff4bad5c60367d7ab4dbe63da94c9528
MD5 8f4cec678438493a2064e3a8d6e5053e
BLAKE2b-256 3c505293a102540b1d0620b519bcff98f4cf1d5ad3f277245bfbca6e94d9f484

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-win32.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f6d1c482093456b68d60f08fdb20b47c25ee6ccaac977282ba64acfb4fb72ff3
MD5 ab3566d1d36d4a5cc3051e081f4b1247
BLAKE2b-256 a973e466e0762f87bda3b6effb58907f2317724670bddd0ed8c781f295cd2e52

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47df81a863e07397e5e4b5303f51bfffd35ca2854da1f760b13caa80b5264ce1
MD5 4e4237598afd163a26f66c4d4a076e1e
BLAKE2b-256 07da08a2f2a0f9efc9c45df5fcbe5e1acf0e29514291b5894f9c1499a4195f0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d9c36ada49f841cd93ba4053fa6e7524543b87dd28471c53b145ae64bb59e27f
MD5 7f16d8a4c1fd2cd519ab469aa3ca19df
BLAKE2b-256 751b2fc99589418d2ac0232c58891484231c9f046ea8153f7ba12c79729cbf97

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 331b9151bb283b8c7d7bc2b3d0e9daf87ad27b001d8eb15c18d2a7f19ce75789
MD5 a610250ee977c325ecef4cf83d54b4bd
BLAKE2b-256 85335b18827435a779bb672c40bb211af4817be07e71c917a8fbb61a3ab7c608

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

File details

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

File metadata

File hashes

Hashes for pynanoid-0.1.1-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 64ba3f6b9c646a540f097640e34c8f270c8906e97a6e75dccdf455303336ad2c
MD5 cde49d3af1cd9e493dda640d931308b9
BLAKE2b-256 62f5add09d207b5723de69e5e0c6c0fc5f86033ddc3d200cac66d770e80136fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynanoid-0.1.1-cp39-abi3-macosx_10_9_x86_64.whl:

Publisher: ci.yml on arunanshub/pynanoid

Attestations:

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