This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!
Project Description


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:


Feed the numbers 0-5 thru Encoder('aaaddddd', password='jupiterx').

You can reverse the process, turning these ids back into 0-5.


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.


Checkout the source and run python 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)



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)



Inserting Constant Characters (Punctuation)

enc = Encoder('ad/ddd-a.d', password='Jupiterz')
for i in range(5):
  print enc.encode(i)



Idgen treated the punctuation characters as constant because they are not keys in the types map.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
idgen-0.0.1.tar.gz (4.1 kB) Copy SHA256 Checksum SHA256 Source Nov 17, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting