Python Nanoid
A tiny, secure, URL-friendly, unique string ID generator for Python.
pip install nanoid
The main module uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters (to have a collision probability similar to UUID v4).
from nanoid import generategenerate() # => NDzkGoTCdRcaRyt7GOepg
Symbols
-,.()are not encoded in the URL. If used at the end of a link they could be identified as a punctuation symbol.
If you want to reduce ID length (and increase collisions probability), you can pass the length as an argument.
from nanoid import generategenerate(size=10) # => "IRFa-VaY2b"
Don’t forget to check the safety of your ID length in ID collision probability calculator.
If you want to change the ID's alphabet or length you can use the internal generate module.
from nanoid import generategenerate('1234567890abcdef', 10) # => "4f9zd13a42"
Non-secure API is also available:
from nanoid import non_secure_generatenon_secure_generate('1234567890abcdef', 10)
nanoid-dictionarywith popular alphabets to use.