nats-counters
Distributed counters built on NATS JetStream streams.
A counter is a JetStream stream configured with allow_msg_counter (ADR-49,
requires nats-server 2.12+). Each subject in the stream is an independent,
arbitrary-precision counter, and increments are atomic.
Install
uv add nats-counters
Usage
from nats.client import connect
from nats.jetstream import new as jetstream
from nats import counters
nc = await connect("nats://localhost:4222")
js = jetstream(nc)
stream = await js.create_stream(
name="COUNTERS",
subjects=["events.>"],
allow_msg_counter=True, # enable counters
allow_direct=True, # required for reads
)
counter = counters.from_stream(js, stream)
# Increment / decrement; returns the new total.
await counter.add("events.orders", 1) # -> 1
await counter.add("events.orders", 10) # -> 11
await counter.add("events.orders", -1) # -> 10
# Read the current value.
await counter.load("events.orders") # -> 10
# Full entry with the last increment and source history.
entry = await counter.get("events.orders")
entry.value # 10
entry.incr # -1
entry.sources # {source_id: {subject: value}} or None
Or wrap an existing stream by name:
counter = await counters.get_counter(js, "COUNTERS")
Status
Single-subject operations (add, load, get), batch and wildcard queries
(get_multiple), and source tracking are implemented. Batch queries use the
batch direct get support provided by nats-jetstream-extra.
License
Apache 2.0
Metadata
Release files for nats-counters 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nats_counters-0.1.0.tar.gz | 4.2 kB | Without provenance | Details for nats_counters-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nats_counters-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for nats_counters-0.1.0-py3-none-any.whl |
Total release size: 9.3 kB
Release files / nats_counters-0.1.0.tar.gz
| Download URL | nats_counters-0.1.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f11e4e36c9f97ad62e20ae9c18d7ce1e2ab7b10aa97029e21e70f317b87ef14c
|
|
BLAKE2b-256 checksum How to use checksums |
5c08dd4abac8f54bf7c543c869393499c55402f3c5e449e1259b6d88ca928408
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / nats_counters-0.1.0-py3-none-any.whl
| Download URL | nats_counters-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7152ca4fca12afee1daaa9a0d11242fd27738ee5cdfadcba0ad7cbbdf94d40a3
|
|
BLAKE2b-256 checksum How to use checksums |
8b907d4101fcc6118d631fa49f40bf0f3a51245c16eaefc661323267adcfa702
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for nats-counters 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.