sifr
… and with the sign 0 … any number may be written
—Fibionacci
Count things in various time based windows using in-memory, redis or riak storage.
Installation
Install the basic package:
pip install sifr
Install sifr with redis dependencies:
pip install 'sifr[redis]'
Install sifr with riak dependencies:
pip install 'sifr[riak]'
Install sifr with sifrd service dependencies:
pip install 'sifr[daemon]'
Examples
Using sifr with direct storage
import datetime
import redis, riak
from sifr.span import Year, Month, Day, Hour, Minute, get_time_spans
from sifr.storage import MemoryStorage, RedisStorage, RiakStorage
redis_client = redis.Redis()
redis_store = RedisStorage(redis_client)
riak_client = riak.RiakClient()
riak_store = RiakStorage(riak_client)
memory_store = MemoryStorage()
stores = [memory_store, redis_store, riak_store]
now = datetime.datetime.now()
user_id = 1
page = "index.html"
# construct the windows. These are the resolutions that will be tracked.
spans = [
span(now, ["views", "user", user_id])
for span in [Year, Month, Day, Hour, Minute]
]
# incr a counter for all resolutions
[store.incr_multi(spans) for store in stores]
# incr a unique counter
[store.incr_unique_multi(spans, page) for store in stores]
[store.incr_unique_multi(spans, page) for store in stores]
# track the page view
[store.track_multi(spans, page) for store in stores]
[store.track_multi(spans, page) for store in stores]
# get the counts/uniques for a single year window
for store in stores:
assert 1 == store.count(Year(now, ["views", "user", 1]))
assert 1 == store.cardinality(Year(now, ["views", "user", 1]))
assert set(["index.html"]) == store.uniques(Year(now, ["views", "user", 1]))
# get the counts/uniques for a range
start = now - datetime.timedelta(minutes=1)
end = now + datetime.timedelta(minutes=1)
span_range = get_time_spans(start, end, ["views", "user", 1], [Minute])
for store in stores:
assert [1] == [store.count(span) for span in span_range]
assert [1] == [store.cardinality(span) for span in span_range]
assert [set(["index.html"])] == [store.uniques(span) for span in span_range]
Using sifr via rpc
sifr.yml (using a redis backend)
storage: redis
redis_url: redis://localhost:6379/1
host: localhost
port: 6000
sifr.yml (using a riak backend)
storage: riak
riak_nodes:
- host: localhost
pb_port: 8087
host: localhost
port: 6000
Run the server
sifrd msgpack_server --config=sifr.yml
Interact with the server
from sifr import RPCClient
client = RPCCient(host='localhost', port=6000, resolutions=["year", "month", "day"])
client.incr("views:user:1")
client.incr_unique("views:user:1", "index.html")
client.incr_unique("views:user:1", "index.html")
client.track("views:user:1", "index.html")
client.track("views:user:1", "index.html")
assert 1 == client.count("views:user:1", datetime.datetime.now(), "day")
assert 1 == client.cardinality("views:user:1", datetime.datetime.now(), "day")
assert set(["index.html"]) == client.uniques("views:user:1", datetime.datetime.now(), "day")
References
Changelog
0.0.4 2015-06-16
Removed transactional pipelines from redis storage.
0.0.3 2015-06-10
Initial release
Metadata
Release files for sifr 0.0.4
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 |
|---|---|---|---|---|
| sifr-0.0.4.tar.gz | 224.3 kB | Without provenance | Details for sifr-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sifr-0.0.4-py2.7.egg | Legacy Egg format | - | - | Details for sifr-0.0.4-py2.7.egg |
Total release size: 262.3 kB
Release files / sifr-0.0.4.tar.gz
| Download URL | sifr-0.0.4.tar.gz |
|---|---|
| Size | 224.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fed1170cc039435fdce29a3d1235e4ef1c5e5710925419917d9863a5f25205e8
|
|
BLAKE2b-256 checksum How to use checksums |
b3affcbe9f214281f800ee716fa15a874550a1489f3fa315b8636ec391e87c3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / sifr-0.0.4-py2.7.egg
| Download URL | sifr-0.0.4-py2.7.egg |
|---|---|
| Size | 38.0 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
15162585d941d95cc8fd777d4c8f4feb17bbfd7599b998304c9ee89be98ad86e
|
|
BLAKE2b-256 checksum How to use checksums |
8587cfe73689ba349f548675f55bec88e2f9424bb5f0bc5c8c19b7f2e141d732
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sifr 0.0.4
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.