Introduction
idgen lets you generate unique identifiers that:
match a desired format;
look random (if you activate crypto);
can be converted back to ints, given the password; and
use ALL possible values in the forma
Let’s say you want to generate IDs like:
vis90000 suu54581 qcr00006 pcg75148 yuy22283 low69877
Feed the numbers 0-5 thru Encoder('aaaddddd', password='jupiterx').
You can reverse the process, turning these ids back into 0-5.
Questions
Q: Why not use incrementing integers as identifiers?
A: You may want to conceal from outsiders how rapidly objects are being created. You may want specific formats that use less characters than base10 but are human-friendly.
Q: Why not randomly generate identifiers?
A: If you want to avoid issuing the same id twice, you need to look up each new id in a database or map. As the number of issued ids grows, the number of lookups per new id grows. If you only plan to use a tiny portion of the available keyspace, this is acceptable, but inelegant compared to just encrypting an int.
Q: Why not just encrypt an integer with AES or something?
A: Because the output of the block cipher is a fixed size, which is not likely to match your desired format.
A format of digits and uppercase letters, for instance, has 10**A * 26**B values.
The 128-bit outputs of AES would take 39 decimal digits to encode.
If you truncate the output of the block cipher, the ids are no longer unique or reversible.
Installation
Checkout the source and run python setup.py install.
Using Idgen
from idgen import Encoder
enc = Encoder('adad', password='Jupiterx')
id = enc.encode(13) # f6d9
i = enc.decode(id) # 13
This creates an encoder which encodes/decodes strings of the form letter-digit-letter-digit. There are 26*10*26*10 such strings, so the encoder can handle integers from 0 to n-1.
Using Different Character Sets
enc = Encoder('wpwpw', types={'w': 'VWXYZ', 'p': '!@#$%^&*()'}, password='Jupitery')
for i in range(5):
print enc.encode(i)
Produces:
X$X&X Y%W(W V!W$V Z)V@Y V)X)X
Encoding Without Encryption
If you just want to convert between integers and some alphanumeric representation:
enc = Encoder('aaa')
for i in range(200, 205):
print enc.encode(i)
Produces:
ahs aht ahu ahv ahw
Inserting Constant Characters (Punctuation)
enc = Encoder('ad/ddd-a.d', password='Jupiterz')
for i in range(5):
print enc.encode(i)
Produces:
j7/739-l.5 x2/319-z.2 w9/274-i.8 z5/166-m.9 v3/500-p.3
Idgen treated the punctuation characters as constant because they are not keys in the types map.
Metadata
Release files for idgen 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| idgen-0.0.1.tar.gz | 4.1 kB | Without provenance | Details for idgen-0.0.1.tar.gz |
Release files / idgen-0.0.1.tar.gz
| Download URL | idgen-0.0.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a1a4a4ae8a72773542118eeb6ea4ccfce82101294c6ab2410ad06c5232a561f
|
|
BLAKE2b-256 checksum How to use checksums |
d2c6d5cd121f50b4b62bd7e78cd316a61a1cdbe163c091adeb63c0907b25dbd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for idgen 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.