Control the exported members for your modules
Project description
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
exports
object 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
exports
attribute 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.
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
File details
Details for the file modul-0.2.0.post0.tar.gz
.
File metadata
- Download URL: modul-0.2.0.post0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1caca5024c3437ea3dc38a0aa51576071f70cde2b91ed4ed7fbcb4e207c2f355 |
|
MD5 | 156bd8e56c1866f6d0ad3cf50ba35749 |
|
BLAKE2b-256 | c0d62cf33c2f1f48fd3fcab140744fd4535b8e4c07ff357d398f871456e92a56 |
File details
Details for the file modul-0.2.0.post0-py3-none-any.whl
.
File metadata
- Download URL: modul-0.2.0.post0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 780ca04b649a945c2373f8ce242f1072cda13d1f431c5ae14415fc033aa084fe |
|
MD5 | 6fd47d815f451962e350e80b214a6afc |
|
BLAKE2b-256 | 22040fb56c0e08cc3ea2e1f40fede8cb8370804945c312afa18b0c2340da0551 |