A Python module privacy checker for keeping public interfaces intentional.
Project description
Privata
Find Python code that looks public but is only used privately.
Privata is a static checker for keeping module boundaries intentional. It scans your production Python modules and reports three kinds of interface drift:
- public top-level functions, classes, variables, and type aliases that are only used inside their own module
- imports of private modules such as
pkg._internalfrom outside their owning package subtree - literal
__all__declarations that are stale, incomplete, or exporting names that do not exist
It is designed for packages and applications where helper() should become _helper() once it is no longer part of the production interface.
Test imports do not count, so tests can still reach internals without forcing those internals to stay public.
Example
Given:
# src/example/service.py
def helper() -> int:
return 1
def run() -> int:
return helper()
Privata reports:
Found 1 public symbols that could be made private:
src/example/service.py:1: function `helper`
Install
uv tool install privata
For local development:
uv sync --extra dev --group docs
uv run pre-commit install
Usage
Run Privata from a project root:
privata .
Privata uses tach.toml source_roots when present.
Otherwise it prefers src/ when that directory exists, and falls back to scanning the project root while ignoring tests, virtualenvs, build output, docs output, and hidden tooling directories.
Use Privata as a pre-commit hook in another repository:
repos:
- repo: https://github.com/basnijholt/privata
rev: v0.1.2
hooks:
- id: privata
For a less strict setup that only runs when requested:
repos:
- repo: https://github.com/basnijholt/privata
rev: v0.1.2
hooks:
- id: privata-manual
pre-commit run --hook-stage manual privata-manual --all-files
Full output can include multiple issue types:
Found 2 public symbols that could be made private:
src/example/service.py:12: function `helper`
src/example/service.py:21: class `InternalState`
Found 1 private module imports outside their package subtree:
src/example/api.py:3: imports private module `example.worker._runtime`
Found 1 __all__ export issues:
src/example/__init__.py:5: public name `Service` missing from __all__
If the project is clean:
No module privacy issues found.
What Privata Checks
- Public top-level functions, classes, variables, and type aliases in production source roots.
- Whether those symbols are imported by another production module under those roots.
- Whether private modules such as
pkg._internalare imported outside their containing package subtree. - Whether literal
__all__declarations exactly match public top-level bindings. - Console entry points in
pyproject.toml. - Uvicorn entry points in shell scripts and Dockerfiles.
- Symbols exported through package
__init__.pyand__all__. - Tach
[[interfaces]]entries, whentach.tomlis present.
Privata intentionally ignores imports from tests/.
If only tests import a symbol, Privata treats that symbol as private.
Development
uv run pytest # enforces 100% coverage
uv run pre-commit run --all-files
uv build
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 privata-0.1.6.tar.gz.
File metadata
- Download URL: privata-0.1.6.tar.gz
- Upload date:
- Size: 63.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff189bcaf1c5b8bc12e54b8756c8456df4daee52916b8191952f1b07338dbd06
|
|
| MD5 |
4fb03fdeedae861aed184ea8dad92952
|
|
| BLAKE2b-256 |
c8bc5ec06ff2878fb9d744886395c2b5ba89b18fe2030508ea498dd7dbca9b4a
|
Provenance
The following attestation bundles were made for privata-0.1.6.tar.gz:
Publisher:
release.yml on basnijholt/privata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privata-0.1.6.tar.gz -
Subject digest:
ff189bcaf1c5b8bc12e54b8756c8456df4daee52916b8191952f1b07338dbd06 - Sigstore transparency entry: 1444350355
- Sigstore integration time:
-
Permalink:
basnijholt/privata@293b64c373c859a40b015f80bace6d710f004074 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@293b64c373c859a40b015f80bace6d710f004074 -
Trigger Event:
release
-
Statement type:
File details
Details for the file privata-0.1.6-py3-none-any.whl.
File metadata
- Download URL: privata-0.1.6-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27b66ad6eaef45703b826209c686c929140d0c29772f58932a12ef8149bce480
|
|
| MD5 |
743ec4e72eecb3ada107c19d43c5d2f4
|
|
| BLAKE2b-256 |
763d2ba6f47d847ed0f42fd73a74d30336c42a5647322af283f4db2467702448
|
Provenance
The following attestation bundles were made for privata-0.1.6-py3-none-any.whl:
Publisher:
release.yml on basnijholt/privata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privata-0.1.6-py3-none-any.whl -
Subject digest:
27b66ad6eaef45703b826209c686c929140d0c29772f58932a12ef8149bce480 - Sigstore transparency entry: 1444350441
- Sigstore integration time:
-
Permalink:
basnijholt/privata@293b64c373c859a40b015f80bace6d710f004074 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@293b64c373c859a40b015f80bace6d710f004074 -
Trigger Event:
release
-
Statement type: