globalstash
Thread-safe, process-wide global state you can import from any module at any depth, with no sys.path tricks.
pip install globalstash
Usage
from globalstash import g
# anywhere in your app
g.db_pool = create_pool()
g["config"] = {"debug": True}
g.get("missing", "default")
g.setdefault("cache", {})
g.update(env="prod", version="1.0")
"db_pool" in g
del g.db_pool
Because Python caches modules, every from globalstash import g returns the same object.
Atomic and compound operations
g.incr("requests") # atomic counter
with g.lock: # read-modify-write
g.total = g.total + 1
Named namespaces
from globalstash import get_state
cache = get_state("cache") # same name -> same object everywhere
cache.ttl = 60
Tests
with g.temporary(debug=True):
... # values restored on exit
Notes
- Method names (
get,pop,update, ...) can't be used as attribute keys; useg["get"]. - State lives per process. Gunicorn/Uvicorn workers each have their own copy. Use Redis or a database for state shared across processes.
- For per-request state (like
flask.g), usecontextvarsinstead.
License
MIT
Metadata
Release files for globalstash 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 |
|---|---|---|---|---|
| globalstash-0.1.0.tar.gz | 5.1 kB | Without provenance | Details for globalstash-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| globalstash-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for globalstash-0.1.0-py3-none-any.whl |
Total release size: 10.1 kB
Release files / globalstash-0.1.0.tar.gz
| Download URL | globalstash-0.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f21333ba2306f20022177880fc787d922739c95f45132fb8c74cd45babe30d7c
|
|
BLAKE2b-256 checksum How to use checksums |
7083174dda673bfacfa256b90409744b47ec6543bef3265a446173dd73cc4638
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / globalstash-0.1.0-py3-none-any.whl
| Download URL | globalstash-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f1320c5b2aecc574c9472db2a0f9407c01a67d3a5b18a8a2b0305f2009a503a
|
|
BLAKE2b-256 checksum How to use checksums |
476612a668ebfe9669f9d06be9524123b5adb67ef1601cfdbd6d2b84b5007cbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for globalstash 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.