Python package module encapsulation toolkit - Enforce public/private symbols at import time
Project description
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
[!Warning] This package must only be imported from a package’s
__init__.py.
# 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
[!Important] Public symbols are determined following the Library interface rules.
-
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file symbol_export-1.0.1.tar.gz.
File metadata
- Download URL: symbol_export-1.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a7d3060395f69e0fdba53bceaf546f5da5ec6893038bbeaa509705531225de8
|
|
| MD5 |
7ae24a4a748c0846e66fff9f564533d4
|
|
| BLAKE2b-256 |
22fb81ed61d320ddda0f2e7ce86178887b4a15ff0bdd80632469039dacc7a663
|
File details
Details for the file symbol_export-1.0.1-py3-none-any.whl.
File metadata
- Download URL: symbol_export-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c20605f99131a30facc64c0f3bc7cde74b071f1c1dc08a1af83e0bb94e2be601
|
|
| MD5 |
8d809d2466d35afd3c11d68b2766548f
|
|
| BLAKE2b-256 |
496a20d16a0ac9fae7d73180abc2c6a61f8372dcf6565fb6a17d3fffc7766ec7
|