Store and retrieve metadata in any object.
Project description
Hafersack
Hafersack is a really small library to store and retrieve metadata in any object. Hafersack can store anything and uses strings as keys.
Installation
$ pip install hafersack # or use your preferred package manager
How to use
Creating a singleton Hafersack instance is recommended, but not required. As long as you use the same key, you can access the same metadata from different Hafersack instances.
from hafersack import Hafersack
sack = Hafersack()
class MyClass:
pass
obj = MyClass()
sack.set(obj, "key1", "value1")
sack.set(obj, "key2", 42)
assert sack.has(obj, "key1")
assert sack.has(obj, "key2")
assert not sack.has(obj, "key3")
assert sack.get(obj, "key1") == "value1"
assert sack.get(obj, "key2") == 42
sack.delete(obj, "key1")
assert not sack.has(obj, "key1")
assert sack.has(obj, "key2")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hafersack-0.1.0.tar.gz.
File metadata
- Download URL: hafersack-0.1.0.tar.gz
- Upload date:
- Size: 1.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.23 {"installer":{"name":"uv","version":"0.9.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e79ef3922681312dec39ccbb2d3f9069b5e36c6f2e596ceedacf0fb1e3822991
|
|
| MD5 |
3a2c63789058825ec992739b2abd882b
|
|
| BLAKE2b-256 |
0e68812dc3da9569a1997834789a239aa8dd12f2e352b784889cdc1a9b55cbef
|
File details
Details for the file hafersack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hafersack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.23 {"installer":{"name":"uv","version":"0.9.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8003d5eb674eb214e296ea82999cc647cae464ab1f3772a27eb0def750d1d606
|
|
| MD5 |
3ffdc59f9b10121bc0b09439187cbd20
|
|
| BLAKE2b-256 |
88a19bc3344e7e1e42924c40bd8074cf60a28205d1158dda693d23918f7c25df
|