intermodule
This library makes it possible to share global variables across modules.
Installation
pip install intermodule
Api Reference
class intermodule.SharedGlobal
Instances of this class manage a global variable and keep it synchronized across modules.
You should never instantiate this class directly. Instead, use set_global and get_global functions.
This class inherits a variant of ObjectProxy from wrapt.
Along with all augmented assignment operators, this class also overloads the normal assignment operator (=) thanks to assign-overload.
Underlying global variable can be any object and the resulting instance of this class will act like that object in every way.
If you use this class, you need to call intermodule.patch_and_reload_module().
You can also access this function from assign_overload module.
You can find documentation about this function in assign-overload.
SharedGlobal.set_global(name, value)
Creates a new SharedGlobal instance with the given name and value but doesn't return it.
Instead, assigns it to the calling module.
Lastly, assigns it to every module which has a global variable whose name is name and whose value is a SharedGlobal instance.
SharedGlobal.get_global(name)
Search through every module for a already defined global variable named name.
If found, check if it is a SharedGlobal instance.
If it is, assign its value to the calling module. The value won't be returned.
If no module defines a variable named name or if its value is not a SharedGlobal instance, raise an error.
Example
# module1.py
import intermodule
intermodule.SharedGlobal.set_global("x", 10)
def main():
global x
import module2
module2.func1()
print(x) # prints 20
x = 30
module2.func2()
if intermodule.patch_and_reload_module():
main()
# module2.py
import intermodule
intermodule.SharedGlobal.get_global("x")
def func1():
global x
x = 20
def func2():
print(x) # prints 30
if intermodule.patch_and_reload_module():
pass
Metadata
Release files for intermodule 1.0.0.post1
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 |
|---|---|---|---|---|
| intermodule-1.0.0.post1.tar.gz | 2.4 kB | Without provenance | Details for intermodule-1.0.0.post1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| intermodule-1.0.0.post1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for intermodule-1.0.0.post1-py2.py3-none-any.whl |
Total release size: 5.4 kB
Release files / intermodule-1.0.0.post1.tar.gz
| Download URL | intermodule-1.0.0.post1.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37d27fad6b059677cc00e452009f453d8f02dda466e146566e858d4749ee5ffe
|
|
BLAKE2b-256 checksum How to use checksums |
6a4b2cdbfcff3e0760adc2dfc64ebde8329fa8dc2bf4821178e5cd58a961c274
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / intermodule-1.0.0.post1-py2.py3-none-any.whl
| Download URL | intermodule-1.0.0.post1-py2.py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b1beadeb2f5d57f522683020f1badc9e4d85ed1f5e7973fda6096bbce3efda4f
|
|
BLAKE2b-256 checksum How to use checksums |
4ad7e22a53857cdab4621420545d03185a59ff1dc01aabeecd88d030a844e924
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for intermodule 1.0.0.post1
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.