atomic-counter 0.1.4
pip install atomic-counter
Released:
Atomic Counters
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- Author: Tim Paine
- Requires: Python >=3.8
-
Provides-Extra:
develop
Classifiers
- Development Status
- Programming Language
Project description
Atomic Counter
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(base_in_nanos)
c.next() # generate next number in sequence
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.
There is also a TimeCounter
class provided. A 64 bit unsigned integer is created that is monotonically increasing, and allows for converting to microseconds to serve as a timestamp (up to the year 2112). Will break if more than 4096 calls to "next" are called within a single microsecond (which is almost assuredly never going to be physically possible, every call makes a system call to get the current time).
from atomic_counter import TimeCounter
from datetime import datetime, timezone
c = TimeCounter()
x = c.next() # generate id
x_time = TimeCounter.to_datetime(x) # generates the datetime where the value was called.
now = datetime.now(timezone.utc)
assert x_time <= now
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
- Author: Tim Paine
- Requires: Python >=3.8
-
Provides-Extra:
develop
Classifiers
- Development Status
- Programming Language
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Uploaded
CPython 3.7+
Windows x86-64
Uploaded
CPython 3.7+
manylinux: glibc 2.17+ x86-64
Uploaded
CPython 3.7+
macOS 11.0+ x86-64
Uploaded
CPython 3.7+
macOS 11.0+ ARM64
File details
Details for the file atomic_counter-0.1.4.tar.gz
.
File metadata
- Download URL: atomic_counter-0.1.4.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c221aa80581b98c288c6833ac06e0cf74e2081bd40e0e5dcda67f590bc2739bb |
|
MD5 | 100a96293eb7b3b9a560efd3f535d56a |
|
BLAKE2b-256 | 235cddd8b4179739dd1eccad4d60ad7aba0353cecdb63b51d5309f99e9f028a0 |
File details
Details for the file atomic_counter-0.1.4-cp37-abi3-win_amd64.whl
.
File metadata
- Download URL: atomic_counter-0.1.4-cp37-abi3-win_amd64.whl
- Upload date:
- Size: 121.5 kB
- Tags: CPython 3.7+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac8dfc801b14c9759c0e105593765f260abb90ec7d72c0d3be9bc696a621f3a |
|
MD5 | c45e0c8f9f70cd1d3cbf82576f28bbd4 |
|
BLAKE2b-256 | ce868f818b379752dd8f0f40e1128fca8454b74c80228f497fa005bc54d39724 |
File details
Details for the file atomic_counter-0.1.4-cp37-abi3-win32.whl
.
File metadata
- Download URL: atomic_counter-0.1.4-cp37-abi3-win32.whl
- Upload date:
- Size: 117.0 kB
- Tags: CPython 3.7+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b165e154ac8fd91bc30c10158706946cb8f1296a43f7e450bb09e2f6cc9bfd0 |
|
MD5 | abe2c7a1bf35b0abe6857948ff8a1a45 |
|
BLAKE2b-256 | c8bc37a4de3f7029f314e85f7638eb2d679c91065d6cab6d7f797e79c5fa2a17 |
File details
Details for the file atomic_counter-0.1.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: atomic_counter-0.1.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 241.2 kB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 358d42034de019d90acd5a3440d643eaa5acf9fe52097c1e7d473d90d62148a7 |
|
MD5 | 8f448212c2893471b99dcb86bde3f7d1 |
|
BLAKE2b-256 | f870e706b92cd9be248ff61d8b739b6298f13df9505025a8aff7dc2fc11aa6d7 |
File details
Details for the file atomic_counter-0.1.4-cp37-abi3-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: atomic_counter-0.1.4-cp37-abi3-macosx_11_0_x86_64.whl
- Upload date:
- Size: 220.5 kB
- Tags: CPython 3.7+, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a44180f20658079eb5f2847f851fcf42b4518d2d39bcbf147bcd18b7211e5aa |
|
MD5 | 40343ad952f3b7307af59e079a4e9a8d |
|
BLAKE2b-256 | 2ad11035e5ca71740a9553fcc1e07144c29ff9a50d63405d298498b55f8d713e |
File details
Details for the file atomic_counter-0.1.4-cp37-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: atomic_counter-0.1.4-cp37-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 209.4 kB
- Tags: CPython 3.7+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf58b0762048ba021c7a6fe6c20d44a970c11896189b88f7aae18f9af38a388 |
|
MD5 | 6ca4d3a85de0e532af4baa5f664ba83e |
|
BLAKE2b-256 | de1864be6a8c74e1ecd6739432c7e7834506d55a3693c88877f0b3683f380d40 |