A simple and efficient probabilistic counter, suited for rate limiting and counting efficiently, without uploading every action to the remote database.
Usage
Instructions
from probcount import ProbCounter
from functools import partial
pc = ProbCounter()
def old_increase_function(counter_name, value):
# run the real call to the DB increasing the counter
# for a redis
# return redis.Redis().incrby(name=counter_name, amount=value)
# or a MongoDB
# return (pymongo.MongoClient().database_name.collection_name.find_one_and_update({"_id": counter_name},
{"$inc": {"value": value}},
{"value": 1}).get("value", 0) + value)
pass
def old_get_function(counter_name):
# run the real call to the DB increasing the counter
# for a redis
# redis.Redis().get(name=counter_name)
# or a MongoDB
# pymongo.MongoClient().database_name.collection_name.find_one({"_id": counter_name}, {"value": 1}).value
pass
pc.create("name_of_counter", partial(old_increase_function, "name_of_counter"), partial(old_get_function, "name_of_counter"))
pc.inc("name_of_counter", 42.0)
pc.get("name_of_counter")
Supported Python Versions
Python Project Template supports the following versions out of the box:
CPython 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7
PyPy 1.9
Release files for probcount 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| probcount-0.1.tar.gz | 17.3 kB | Details |
Release files / probcount-0.1.tar.gz
| Download URL | probcount-0.1.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a2ee525e7cd6868ec3fc3bfa5893192e605bd211db7fb2366165c2dbcd020d9
|
|
BLAKE2b-256 checksum How to use checksums |
1ccad33fbeba0f9b9fdf835e93757a3caf95bd31b82e83a639144801490a78d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |