Skip to content
This repository was archived by the owner on Apr 29, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Anything else is an implementation detail and may change without a major version

## Key design choices

- **Zero external dependencies in the core.** Detection, anonymization, and mapping run on stdlib alone. Heavy features (spaCy, Faker, pdfplumber) are opt-in extras.
- **Minimal dependencies.** Detection, anonymization, and mapping run on stdlib alone; `typer` (used by the CLI) is the only required install-time dep. Heavy features (spaCy, Faker, pdfplumber) are opt-in extras.
- **Checksums written from scratch.** PESEL, NIP, REGON, Luhn, mod-97 IBAN — the library's core value, not outsourced.
- **Reversibility is a contract.** Every `anonymize()` call returns a `Mapping` that enables perfect restoration, preserving source formatting (dashes, spaces).
- **Polish-first.** Native handling of Polish identifiers and, via the `[ner]` extra, Polish names and addresses through `pl_core_news_lg`.
Expand Down
4 changes: 3 additions & 1 deletion src/llm_safe_pl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
implementation detail and may change without a major version bump.
"""

from importlib.metadata import version as _version

from llm_safe_pl.models import AnonymizeResult, Mapping, Match, PIIType
from llm_safe_pl.shield import Shield

__version__ = "0.1.0"
__version__ = _version("llm-safe-pl")

__all__ = [
"AnonymizeResult",
Expand Down
1 change: 0 additions & 1 deletion src/llm_safe_pl/anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(
) -> None:
self._detectors = detectors
self._mapping = mapping
self._strategy = strategy

def detect(self, text: str) -> list[Match]:
"""Find all PII matches with overlaps resolved, without mutating Mapping."""
Expand Down
23 changes: 23 additions & 0 deletions src/llm_safe_pl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import typer

from llm_safe_pl import __version__
from llm_safe_pl.models import Mapping
from llm_safe_pl.shield import Shield

Expand All @@ -27,6 +28,28 @@
)


def _version_callback(value: bool) -> None:
if value:
typer.echo(__version__)
raise typer.Exit()


@app.callback()
def _root(
version: Annotated[
bool,
typer.Option(
"--version",
"-V",
callback=_version_callback,
is_eager=True,
help="Show the version and exit.",
),
] = False,
) -> None:
"""llm-safe-pl — reversible PII anonymization for Polish documents."""


def _read_text(path: Path) -> str:
"""Read a text file, accepting UTF-8 (±BOM) and UTF-16 (±endianness) with BOM."""
data = path.read_bytes()
Expand Down
13 changes: 13 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typer.testing import CliRunner

from llm_safe_pl import __version__
from llm_safe_pl.cli import app


Expand All @@ -14,3 +15,15 @@ def test_cli_help_exits_zero() -> None:
def test_cli_no_args_shows_help() -> None:
result = CliRunner().invoke(app, [])
assert "Usage" in result.output


def test_cli_version_flag_prints_version() -> None:
result = CliRunner().invoke(app, ["--version"])
assert result.exit_code == 0
assert __version__ in result.output


def test_cli_short_version_flag_prints_version() -> None:
result = CliRunner().invoke(app, ["-V"])
assert result.exit_code == 0
assert __version__ in result.output
Loading