Skip to main content

Atomic Counters

Project description

Atomic Counter

Build Status Coverage License PyPI

Overview

atomic-counter is a rust library for generating a monotonically increasing sequence of integers. Depending on the particular configuration of the counter, the generated sequence will be produce unique numbers down to the nanosecond, regardless of memory state. E.g. if you quit the process and recreate a new counter >1ns later, your sequence is guaranteed to still be monotonically increasing (but with a gap).

Usage

from atomic_counter import Counter

c = Counter(offset_in_nanos, base_in_nanos)

c.next()  # generate next number in sequence

Here, base is the counter's 0 value (e.g. a epoch in nanos to consider the 0 point, to keep numbers as small as possible if you do not need to go back to 1970). offset is the number of nanos since base at which to start.

If unset, base will be 2010-01-01 in nanos, offset will be 0, which means the counter will start at (now - 2010/01/01) as nanos.

To create e.g. a daily counter, pass in base=today in nanos. As this is a common occurrence for sequences that reset daily, a convenience function def daily() -> Counter: is provided.

Project details


Download files

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

Source Distribution

atomic_counter-0.1.2.tar.gz (17.8 kB view hashes)

Uploaded Source

Built Distributions

atomic_counter-0.1.2-cp37-abi3-win_amd64.whl (114.9 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

atomic_counter-0.1.2-cp37-abi3-win32.whl (108.7 kB view hashes)

Uploaded CPython 3.7+ Windows x86

atomic_counter-0.1.2-cp37-abi3-musllinux_1_1_x86_64.whl (593.1 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ x86-64

atomic_counter-0.1.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (566.2 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

atomic_counter-0.1.2-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (578.0 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

atomic_counter-0.1.2-cp37-abi3-macosx_11_0_arm64.whl (214.0 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

atomic_counter-0.1.2-cp37-abi3-macosx_10_9_x86_64.whl (218.8 kB view hashes)

Uploaded CPython 3.7+ macOS 10.9+ x86-64

atomic_counter-0.1.2-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (426.5 kB view hashes)

Uploaded CPython 3.7+ macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page