shelchemy - Dict-like (shelve-like) storage wrapper for any DBMS (SQLAlchemy)
Python installation
from package
# Set up a virtualenv.
python3 -m venv venv
source venv/bin/activate
# Install from PyPI
pip install shelchemy
from source
git clone https://github.com/shelchemy/shelchemy
cd shelchemy
poetry install
Examples
This library is more useful when used along with hdict.
Here are some possible usages by itself.
Scheduling jobs.
from time import sleep
from shelchemy.scheduler import Scheduler
# Jobs can be distributed across multiple computers/networks.
names1 = ["a", "b"]
names2 = ["c"]
names3 = ["d", "e"]
storage = {}
# `storage` can be: shelve; URI pointing to a database; or, any dict-like object.
# Example of a local database: storage="sqlite+pysqlite:////tmp/sqla-test.db"
# Example of a remote database: storage="mysql+pymysql://user1:password1@hosh.page/db1"
for name in Scheduler(storage, timeout=10) << names1 << names2 << names3:
print(f"Processing {name}")
sleep(0.1)
print(f"{name} processed!")
"""
2023-11-13 00:03:40.115637 'a' is new, starting
Processing a
a processed!
2023-11-13 00:03:40.316130 'a' done
2023-11-13 00:03:40.326101 'b' is new, starting
Processing b
b processed!
2023-11-13 00:03:40.526549 'b' done
2023-11-13 00:03:40.534599 'c' is new, starting
Processing c
c processed!
2023-11-13 00:03:40.735062 'c' done
2023-11-13 00:03:40.745734 'd' is new, starting
Processing d
d processed!
2023-11-13 00:03:40.946152 'd' done
2023-11-13 00:03:40.957263 'e' is new, starting
Processing e
e processed!
2023-11-13 00:03:41.157701 'e' done
"""
Persistent dict.
from shelchemy import sopen
from shelchemy.cache import Cache
d = Cache("sqlite+pysqlite:////tmp/sqla-test.db")
d["x"] = 5
d["b"] = None
print(d["x"], d["b"])
"""
5 None
"""
try:
d["xxx"]
except KeyError as m:
print(m)
"""
'xxx'
"""
for k, v in d.items():
print(k, v)
print("x" in d)
"""
872d417d62b78366a71ab9fee25f14dc None
aed0339093d97301965a4e23dac3424a b'only bytes when autopack=False'
a b'by'
x 5
b None
True
"""
del d["x"]
print("x" in d)
"""
False
"""
print(d)
"""
{'872d417d62b78366a71ab9fee25f14dc': None, 'aed0339093d97301965a4e23dac3424a': b'only bytes when autopack=False', 'a': b'by', 'b': None}
"""
# Using a context manager.
with sopen() as db:
print("x" in db)
print(db)
db["x"] = b"asd"
print(db)
print(db["x"] == b"asd")
print("x" in db)
print(db.x == b"asd")
del db["x"]
print("x" in db)
db["any string key longer than 40 characters will be hashed depending if the DBMS backend is used"] = None
print(db)
"""
False
{}
{'x': b'asd'}
True
True
True
False
{'872d417d62b78366a71ab9fee25f14dc': None}
"""
Grants
This work was partially supported by Fapesp under supervision of Prof. André C. P. L. F. de Carvalho at CEPID-CeMEAI (Grants 2013/07375-0 – 2019/01735-0).
Metadata
Release files for shelchemy 2.240219.2
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 |
|---|---|---|---|---|
| shelchemy-2.240219.2.tar.gz | 21.5 kB | Without provenance | Details for shelchemy-2.240219.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shelchemy-2.240219.2-py3-none-any.whl | Python 3 | none | any | Details for shelchemy-2.240219.2-py3-none-any.whl |
Total release size: 45.1 kB
Release files / shelchemy-2.240219.2.tar.gz
| Download URL | shelchemy-2.240219.2.tar.gz |
|---|---|
| Size | 21.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1a990ce25c90d38e4621e9339109363f7e5791d60c36cd47622fbefab3bdb3b
|
|
BLAKE2b-256 checksum How to use checksums |
477d83aebc68d63a33b65cc6590ea560b019cda2cafafb61776df4cd0f32acbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.6 Linux/5.15.0-91-generic
|
Release files / shelchemy-2.240219.2-py3-none-any.whl
| Download URL | shelchemy-2.240219.2-py3-none-any.whl |
|---|---|
| Size | 23.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a680a829e3e0eda6143c09abc23dcbcac2a403501316e97ea609e216221d7a43
|
|
BLAKE2b-256 checksum How to use checksums |
ed358001617f631a68522a154e7644e147cc520cb36906eda4ee3f5dd7c1ffef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.6 Linux/5.15.0-91-generic
|
Security for shelchemy 2.240219.2
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.