Primary Key Generator Implemented In Python
PkGen is a pk generator implemented using Python, who’s core algorithm derives from Mongo’s generation of ObjectId.
Basic Concept of ObjectId
A BSON ObjectId is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id(PID) and a 3-byte counter. Note tha the timestamp and counter fields must be stored big endian unlike the rest of BSON.
2 ways to install PkGen:
- clone the repo to your machine, run setup.py
$ cd ~ && firstname.lastname@example.org:streethacker/pkgen.git $ python setup.py install
- using pip
$ pip install -e git+https://email@example.com#egg=pkgen
>>> from pkgen import PkGen >>> pkg = PkGen() >>> pk = pkg.pkgen() >>> pk.pk '5735ae95c14e2435aa000000' >>>
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.