Symbol Export
symbol-export is an advanced Python module encapsulation toolkit that enforces true public/private symbol boundaries at import time.
Unlike Python’s conventional visibility mechanisms (_, __all__), this project actively intercepts the import system to ensure that third-party code can only access what a package explicitly declares as public.
🚀 Installation
Available on PyPI
pip install symbol-export
🎯 Project Goal
Python does not provide real encapsulation at the module level.
symbol-export introduces a strict and deterministic mechanism to:
-
Define a clear public API
-
Prevent accidental or unintended access to internal symbols
-
Respect official
__all__semantics -
Enforce visibility rules at import time
✨ Features
-
🔒 Real module encapsulation
-
📦 Strict control of exported symbols
-
🧠 Fully respects
__all__ -
🔁 Automatic handling of package submodules
-
🧩 No changes required in consumer code
-
🪝 Global
__import__hook -
⚙️ Works with transitive imports
-
🧪 Designed for libraries, not scripts
✅ Usage
# mypackage/__init__.py
import __symbol_export__
from mypackage import helpers
_T = "public constant"
def public_function():
...
def _public_function():
...
# mypackage/helpers.py
def _private_helper():
...
class PublicClass:
pass
def public_helper():
...
👤 From third-party code
import mypackage
# ✅ allowed
mypackage._T
mypackage.public_function
mypackage._public_function
mypackage.helpers
mypackage.helpers.PublicClass
mypackage.helpers.public_helper
# ❌ not visible
mypackage.helpers._private_helper
🧠 How It Works Internally
-
Overrides
builtins.__import__ -
Detects which package imports symbol-export
-
Registers that package as an exported package
-
Submodules of the package are also encapsulated automatically
-
Replaces entries in
sys.moduleswith capsule modules -
Capsule modules expose only public symbols
⚠️ Known Limitations
-
Does not encapsulate the
__init__module -
Not compatible with hot-reload systems
-
Not designed for embedded Python runtimes
🔐 Security Considerations
-
This is NOT a sandbox
-
This is NOT a security boundary
-
Does not prevent intentional reflection
-
Does not block access to sys.modules or inspect
-
Does not replace permission systems
✔️ Designed for:
-
Clean public APIs
-
Library contracts
-
Preventing accidental misuse
❌ Not designed for:
-
Protection against malicious code
-
Runtime isolation
-
DRM or code obfuscation
Release files for symbol-export 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| symbol_export-1.0.1.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| symbol_export-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.4 kB
Release files / symbol_export-1.0.1.tar.gz
| Download URL | symbol_export-1.0.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a7d3060395f69e0fdba53bceaf546f5da5ec6893038bbeaa509705531225de8
|
|
BLAKE2b-256 checksum How to use checksums |
22fb81ed61d320ddda0f2e7ce86178887b4a15ff0bdd80632469039dacc7a663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / symbol_export-1.0.1-py3-none-any.whl
| Download URL | symbol_export-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c20605f99131a30facc64c0f3bc7cde74b071f1c1dc08a1af83e0bb94e2be601
|
|
BLAKE2b-256 checksum How to use checksums |
496a20d16a0ac9fae7d73180abc2c6a61f8372dcf6565fb6a17d3fffc7766ec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|