Skip to main content

strictaccess

CI PyPI Python versions Coverage License: MIT Typed: PEP 561

strictaccess enforces Java/C++-style access modifiers on Python classes through the @private, @protected, and @public decorators. Violations raise typed exceptions; an optional debug mode downgrades them to logged warnings.

This is a discipline tool, not a security boundary. See Limitations below.

Installation

pip install strictaccess

Requires Python 3.11+ (the engine relies on frame.f_code.co_qualname, introduced in CPython 3.11).

Quick example

from strictaccess import strict_access_control, private, protected, PrivateAccessError

@strict_access_control()
class Account:
    def __init__(self, balance: int) -> None:
        self._balance = balance        # underscore -> protected by convention

    @private
    def _adjust(self, delta: int) -> None:
        self._balance += delta

    @protected
    def _audit(self) -> str:
        return f"balance={self._balance}"

    def deposit(self, amount: int) -> None:
        self._adjust(amount)            # OK: internal call

acct = Account(100)
acct.deposit(50)                        # OK
acct._adjust(1000)                      # raises PrivateAccessError
acct._balance                           # raises ProtectedAccessError

What each decorator does

Decorator Callable from If called from outside
@public Anywhere (overrides underscore convention) Allowed
@protected Defining class + any subclass ProtectedAccessError
@private Defining class only PrivateAccessError

Plus, the underscore convention is enforced automatically:

Attribute name pattern Treated as
name (no underscore) public
_name protected
__name (name-mangled) private
__name__ (dunder) unrestricted

Debug mode

Replace exceptions with WARNING log records via the strictaccess logger:

import logging
logging.basicConfig(level=logging.WARNING)

@strict_access_control(debug=True)
class Audit:
    @private
    def _secret(self): return 42

Audit()._secret()  # logs a warning, returns 42

Useful for adopting strictaccess on a legacy codebase without stopping production behaviour while you fix call sites.

Limitations

strictaccess enforces discipline at attribute-read time. It is not a security boundary. Specifically:

  • object.__getattribute__(obj, name) bypasses the check entirely.
  • Pickling a decorated instance can fail because the wrapper class is created dynamically by type(...). Use copy.deepcopy instead, or unwrap the instance before pickling.

The full list is documented in docs/limitations.md.

Documentation

Full guide and API reference: https://jhoelperaltap.github.io/strictaccess (generated from docs/).

Contributing

See CONTRIBUTING.md for development setup, test commands, and the contribution flow. Open a discussion before large changes.

License

MIT — see LICENSE.

Metadata

Release files for strictaccess 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strictaccess 1.0.0
File Size Uploaded
strictaccess-1.0.0.tar.gz 28.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for strictaccess 1.0.0
File Interpreter ABI Platform
strictaccess-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.1 kB

Release files / strictaccess-1.0.0.tar.gz

Download URL strictaccess-1.0.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d26bb947f000ddae3eb42c2444884690f9013093d4f396a4ed1f63eda94c3296
BLAKE2b-256 checksum
How to use checksums
239b6144c5b628b84585a7f50780b6c309462f3c9e5120137920cca40dccaed8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Release files / strictaccess-1.0.0-py3-none-any.whl

Download URL strictaccess-1.0.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c61e8070c561461c2d81db8d85eb0c0167f4ef081b3c95061104d9e4f73bb8cc
BLAKE2b-256 checksum
How to use checksums
c4f4c899446959eeda157bab9f1949668a77271b3c9bd355857b2177562b0e76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page