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

An integer id sequence generator using elasticsearch to create bulks of ids. Elasticsearch can not create integer ids for newly created documents. This package helps to be able to create unique integer ids in a distributed system.

Features

  • makes sure multiple processes are able to create unique ids
  • optimized by requesting multiple ids with a single Elasticsearch request

Elasticsearch Setup

Note

It is important to enable dynamic scripting in elasticsearch. Add this to your yaml configuration file:

script.disable_dynamic: false

The sequences must be assigned to an elasticsearch client instance:

>>> from elasticsearch import Elasticsearch
>>> es_client = Elasticsearch(['localhost:%s' % crate_port])

To globally assign the client to all sequences in the application the client can be assigned to the class property ES:

>>> from lovely.essequence import Sequence
>>> Sequence.ES = es_client

Usage

There is a Sequence class:

>>> from lovely.essequence import Sequence

It must be instantiated with the name of a sequence:

>>> s1 = Sequence('s1')

Now the iids can be requested:

>>> s1.next()
1
>>> s1.next()
2

Multiple sequence instances for the same sequence name use the same bulk:

>>> s2 = Sequence('s1', bulk_size=100)
>>> s2.next()
3

After the bulk size has been consumed the request of the next bulk is transparently handled inside the next method:: Consume all the cached ids from s1:

>>> for i in range(10): s1.next()
4
5
6
7
8
9
10
11
12
13

Multiple independed sequences can be used:

>>> other = Sequence('other')
>>> other.next()
1

Transforming the provided iid

A transformation function can be provided to transform the provided integer value into something else when calling next:

>>> asstring = Sequence('other', transform=str)
>>> isinstance(asstring.next(), str)
True

>>> def transformer(iid):
...     return {'iid': iid}
>>> Sequence('other', transform=transformer).next()
{'iid': 3}

Resetting a Sequence

For testing purposes it is possible to reset a sequence.

Note

Resetting a sequence will not work correct if multiple processes use the same sequence. This is for testing only.

>>> s1 = Sequence('reset')
>>> s2 = Sequence('reset')
>>> s1.next()
1
>>> s2.next()
2
>>> from lovely.essequence.sequence import testing_reset_sequences
>>> testing_reset_sequences()
>>> s2.next()
1
>>> s1.next()
2
Release History

Release History

0.1.0

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

0.0.2

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

0.0.1

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
lovely.essequence-0.1.0.tar.gz (3.7 kB) Copy SHA256 Checksum SHA256 Source Jul 30, 2016

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