Registry / testing / publication

publication

JSON →
library0.0.3pypypi✓ verified 27d ago

Publication helps maintain public-api-friendly Python modules by preventing unintentional access to private implementation details via introspection. It's currently at version 0.0.3 and is an early-stage library with a focused purpose.

pip install publication
INSTALL
IMPORT
SIG · PUBLICATION
P
publication
testingpythonv0.0.3
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

publish
from publication import publish

Demonstrates how to use the `@publish` decorator to control the visibility of classes and their members to introspection tools. Note that `publication` affects discoverability, not direct access.

from publication import publish @publish class MyPrivateImplementation: def _secret_method(self): return "This should not be accessible" def public_method(self): return "This is public" # Without publication, you could do: # obj = MyPrivateImplementation() # print(obj._secret_method()) # With publication, the _secret_method will not be exposed by introspection tools. # Direct access still works, but tools won't find it. # Example of usage (not for execution, just demonstrating effect): # If you run dir(MyPrivateImplementation) or use an IDE's autocomplete, # _secret_method should not appear. # For demonstration, direct access still works for runtime logic, but not discovery. obj = MyPrivateImplementation() assert obj.public_method() == "This is public" # print(obj._secret_method()) # This line would still run if uncommented, # but it won't be discovered by introspection.
Debug
Known issues
gotchaPublication works by modifying module `__dict__` and `__all__` at import time. This means it primarily affects tools relying on introspection (debuggers, IDE autocompletion, `dir()`), but it does not prevent direct attribute access if a user knows the name.
fix
Understand that 'private' in this context means 'not discoverable by introspection', not 'inaccessible'.
affects: 0.0.1+
gotchaThis library is intended for API hygiene and clarity, not for security. Do not rely on `publication` to enforce security boundaries or prevent malicious access to internal components, as direct access is still possible.
fix
Use proper security mechanisms (e.g., access control, authorization) for sensitive data or operations.
affects: 0.0.1+
gotchaPublication operates at import time. It may not function as expected or might be bypassed by dynamically loaded modules, modules loaded in unusual ways, or changes to objects made after the initial import process.
fix
Ensure modules are loaded in a standard way. For dynamic scenarios, be aware that its effects might be inconsistent or absent.
affects: 0.0.1+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'publication'
The 'publication' library has not been installed in your Python environment.
fix
Run `pip install publication` in your terminal to install the library.
ImportError: cannot import name 'api' from 'publication'
This error occurs if the 'api' object is not directly importable from the top-level 'publication' module, or if there's a typo in the import statement.
fix
Ensure you are importing `api` correctly based on the library's structure, typically `from publication import api` or `from publication.api import api`. If the error persists, verify the library's documentation for the correct import path.
AttributeError: 'YourClass' object has no attribute '_private_member'
The 'publication' library is designed to prevent unintentional access to non-public (e.g., underscore-prefixed) attributes or methods. This error occurs when you attempt to access such a 'private' member that has not been explicitly exposed via `publication.api()`.
fix
Either ensure the attribute/method you are trying to access is part of the public API by decorating it with `@api` in its definition, or refactor your code to only interact with the publicly exposed API of the module.
Upgrade
Version history
0.0.3latest on PyPI · released Jan 15, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
publication — pip install publication · libregistry