idstring
Python module to create alpha-numeric serial number strings with a check digit, with smart incrementing.
an IDstring is a string-like object which can be incremented, to produce a series of serial-number-like strings, consisting of Arabic digits and upper case letters, skipping those which can be easily misinterpreted ("oh", "I", "Q", and Zed) and which has (by defaut) an optional Luhn-N check digit, capable of detecting any single-letter error and most other errors.
Programmers may define alternate alphabets, alternate lists of "dirty" words (which are skipped), a fixed subfield for generating serial number from multiple sources, and a hash code to create unique check digits algorithms for multiple projects. Passing a hash code of None will surpress check digit operation.
For more explanation, please refer to the wiki on github
class IDstring generates (and checks) alphanumeric serial number strings with a checksum
changes:
-
2018 Update: Still works fine in Python 3.6. No issues have been filed, no bugs reported.
-
2022 Update: works with Python 3.10. Python 2.7 dropped. Version 2.0.1
-
Version 2.0:
-
Added ability to pass hash=None to turn off checksums.
-
Support for lower-case letters in alphabets.
-
Assigning alternate alphabets (etc.) during instance creation.
-
Choice of automatic case shift upper, lower, or None.
-
Some small breaking changes. Especially . . .
-
The use of IdString(seed='sss') syntax is required in usual cases when manually creating a new instance.
-
The wonky 5-bit binary conversion functions, which only worked with the default alphabet, have been removed.
-
Version 2.1:
-
adds a .context dictionary to the IDstring object which a seedstore method can use to store its operating context.
-
Version 2.1.5:
-
Requires Python 3.11 or newer. (Users of older Pythons will continue to get version 2.1.4.)
-
Bug fixes: the .value property now returns the string; IDstring(existing_id) copies the host of an id which has one; my_id.sumcheck() checks the instance using its own hash, alphabet and case_shift; each new IDstring factory gets its own .context dictionary (they had been sharing one).
-
Tests now run automatically on GitHub Actions for every pull request.
operation:
IDstring extends the built-in str class, using an ADD method which accepts the integer ONE. Adding 1 to an instance of the class will generate a new instance with an incremented value (and a new checksum).
So, in short, you can generate serial numbers like this:
serial = idstring.IDstring(seed='1Y3R9C')
while serial.startswith('1'): # notice that it is like a string, so .startswith works.
serial += 1 # Increments the string & generates a new checksum.
print(serial)
Starting from "1Y3R9CB" (the seed plus its check digit), the loop runs 925,387 times, ending with:
1YYYYVA
1YYYYW8
1YYYYX6
1YYYYY4
200000X
Incrementation flows smoothly through the alphabet -- "9" increments to "A". Incrementing "Y" gives "0" and causes a carry to increment the next digit. If you run out of digits, a "1" is prepended to the string. (By default. Alternate alphabets increment in their implied order. The actual code for a new leading digit is: "carry_digit = '1' if self.alphabet[0] == '0' else self.alphabet[0]")
The "Luhn mod N" algorithm is used (unless disabled) to add another digit (from the same alphabet) as a check digit.
The routine will automatically skip over patterns which contain substrings matching a list of "Dirty Words." Without that filter, the above example would have produced 925,396 results; the filter skipped 9 objectionable values.
You can override the supplied alphabet and objectionable word lists. Alternate alphabets overflow correctly.
You may supply an optional call-back function to assist in maintaining the persistence of the serial number sequence of multiple program runs.
The Luhn-N check digit will detect any single character substitution, any inversion of adjacent characters (except the first and last character in the alphabet: i.e. 0<->Y for the supplied default) and most other errors.
The default alphabet consists of [0-9] and [A-Y] dropping "I", "O", and "Q".
Provision is made for a fixed subfield (of user defined length) between the check digit and the incrementing field, so that multiple sites can produce non-overlapping series of numbers. This subfield and the check digit are included in the "dirty word" checking.
still don't understand?
Read the source, Luke. https://pypi.org/project/idstring/#files
Read (and then test run) the program sample_seedstore.py to see how it works.
Run "python sample_seedstore.py" from multiple terminals to observe how it uses a one-row SQL database to maintain the seed value and gives unique values.
installation:
Installation uses the usual Python methods:
pip install idstring
Metadata
Release files for idstring 2.1.5
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 |
|---|---|---|---|---|
| idstring-2.1.5.tar.gz | 15.7 kB | With provenance | Details for idstring-2.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| idstring-2.1.5-py3-none-any.whl | Python 3 | none | any | Details for idstring-2.1.5-py3-none-any.whl |
Total release size: 26.2 kB
Release files / idstring-2.1.5.tar.gz
| Download URL | idstring-2.1.5.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa3916367a2a5eca866597ef03d811d56888b46b6388723263ebbed91c8c5e5a
|
|
BLAKE2b-256 checksum How to use checksums |
ab6b41b7efdd7a9136faaf4e2807b289b55a28009aacfb6a4a98b8bd356288ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / idstring-2.1.5-py3-none-any.whl
| Download URL | idstring-2.1.5-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6bc87db91db97267ba6fd2e3a85f52ce61bf2c76b84f34a9776a3fe001867fd
|
|
BLAKE2b-256 checksum How to use checksums |
7154b8737178ee19964963e03f28a79b1adbbc86614f83c79589d8d495fb65c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for idstring 2.1.5
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for idstring-2.1.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA 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.