Modul
/moˈduːl/
Control the exported members for your modules
Requirements
Modul requires Python >=3.7
Installation
$ python -m pip install modul
Modul is a single-file module with less than 200 lines of code and no dependencies. It can be easily copied into your project.
Quick start
Write a module exporting limited members:
# mymodule.py
from modul import exports
@exports
def foo():
return 42
baz = "unexported"
bar = "hello"
exports.bar = bar
In another module or REPL:
>>> import mymodule
>>> mymodule.foo()
42
>>> mymodule.bar
"hello"
>>> mymodule.baz
AttributeError: Module test has no attribute baz
>>> mymodule.__all__
['foo', 'bar']
Usage
-
Export a function with decorator:
@exports def foo(): return 42
-
Export a variable with attribute set:
exports.bar = 42
Note that to use the variable inside the module, you still need to declare a variable for it:
bar = 42 exports.bar = bar
-
Export a variable with item set:
exports["bar"] = 42
Besides, the
exportsobject supports all APIs ofdict:exports.update({"bar": 42})
-
Export a map of (name, value) pairs:
exports({ "bar": 42, "baz": "hello" })
-
You can even have conditional exports and exports from function call:
flag = True if flag: exports.foo = 42 def export_bar(): exports.bar = 42 export_bar()
-
Alternatively, you can assign members to the
exportsattribute of the module:import modul modul.exports = { "bar": 42, "baz": "hello" }
Note that you can't use
exports = <variable>in this case, because it will lose the reference to the API. And each assignment will overwrite the previous one so there can be only one assignment in your module.
Metadata
Release files for modul 0.2.0.post0
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 | |
|---|---|---|---|---|
| modul-0.2.0.post0.tar.gz | 5.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modul-0.2.0.post0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / modul-0.2.0.post0.tar.gz
| Download URL | modul-0.2.0.post0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1caca5024c3437ea3dc38a0aa51576071f70cde2b91ed4ed7fbcb4e207c2f355
|
|
BLAKE2b-256 checksum How to use checksums |
c0d62cf33c2f1f48fd3fcab140744fd4535b8e4c07ff357d398f871456e92a56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.61.0 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.9
|
Release files / modul-0.2.0.post0-py3-none-any.whl
| Download URL | modul-0.2.0.post0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
780ca04b649a945c2373f8ce242f1072cda13d1f431c5ae14415fc033aa084fe
|
|
BLAKE2b-256 checksum How to use checksums |
22040fb56c0e08cc3ea2e1f40fede8cb8370804945c312afa18b0c2340da0551
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.61.0 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.9
|
Security for modul 0.2.0.post0
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.