Skip to main content

Primary Key Generator Implemented In Python

Project description

Introduction

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.

More

Install

2 ways to install PkGen:

  1. clone the repo to your machine, run setup.py
$ cd ~ && git@github.com:streethacker/pkgen.git
$ python setup.py install
  1. using pip
$ pip install -e git+https://github.com/streethacker/pkgen@0.1#egg=pkgen

Start

>>> from pkgen import PkGen
>>> pkg = PkGen()
>>> pk = pkg.pkgen()
>>> pk.pk
'5735ae95c14e2435aa000000'
>>>

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

pkgen-0.1.tar.gz (2.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page