ShortStr is a Python module to generate unambiguous, homoglyph-less "shortstrings" for URL shortners and similar services.
Project description
ShortStr is a Python module to generate unambiguous, homoglyph-less “shortstrings” for URL shortners and similar services.
pip install shortstr
Websites such as Pastebin have unique alphanumeric strings IDs, like https://pastebin.com/mKxTdEeT. Code like ‘’.join([random.choice(string.ascii_letters + string.digits) for x in range(5)]) can be used to generate strings like ‘DY6iv’, but these can include similar-looking characters (called homoglyphs) like O and 0.
The shortstr module generates these shortstrings without the l, I, o, O, 0, and 1 homoglyphs. It also has checksum and can check for repeat shortstrings to ensure you only produce unique shortstrings, and uses os.urandom() to produce truly random shortstrings, not pseudorandom shortstrings.
Examples
>>> import shortstr >>> shortstr.generate() 'kZXmL9' >>> shortstr.generate('ddddd') '67249f' >>> shortstr.generate('ddddd', includeChecksum=False) '39844' >>> shortstr.generate('ccccc', includeChecksum=False) 'gKXda' >>> shortstr.generate('lllll', includeChecksum=False) 'qibkp' >>> shortstr.generate('uuuuu', includeChecksum=False) 'WWXGC' >>> shortstr.generate('***dddcccllluuu', includeChecksum=False) '5SP534FiBtxtMCG' >>> shortstr.isValid('kZXmL9') True >>> shortstr.isValid('67249f') True >>> shortstr.isValid('invalid shortstring') False
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ShortStr-1.0.0.tar.gz
.
File metadata
- Download URL: ShortStr-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 552b0170a3c45b7405e7a026ec68f6cdc9d628f32364da633f89c48881f3669d |
|
MD5 | 8ca896fba1edb8adc7235f8e2fbb3050 |
|
BLAKE2b-256 | a12ff52a008e1586c74966e4350aeeb1813b6b39c61ca7a145fb9c780c839d3b |