pdf-anonymizer-cli 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/PKG-INFO +12 -1
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/README.md +12 -1
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/pyproject.toml +1 -1
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli/cli.py +61 -38
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/PKG-INFO +12 -1
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/setup.cfg +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli/__init__.py +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli/main.py +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/SOURCES.txt +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/dependency_links.txt +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/entry_points.txt +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/requires.txt +0 -0
- {pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pdf-anonymizer-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: CLI for a tool to anonymize PDF, Markdown, and plain text files using LLMs.
|
|
5
5
|
Author-email: Leonid Ganeline <leo.gan.57@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -131,3 +131,14 @@ pdf-anonymizer deanonymize \
|
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
This will create a deanonymized version of the file at `data/deanonymized/document.deanonymized.md`.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## See Also
|
|
138
|
+
|
|
139
|
+
- **[Main Documentation](https://leo-gan.github.io/anonymizer/)** — Full guides including the 101 course.
|
|
140
|
+
- **[Core Package README](../pdf-anonymizer-core/README.md)** — Details on the underlying library.
|
|
141
|
+
- **[Recipes & Common Workflows](https://leo-gan.github.io/anonymizer/project/recipes/)** — Practical CLI usage examples (profiles, batching, external workflows, etc.).
|
|
142
|
+
- **[CLI Reference (full)](https://leo-gan.github.io/anonymizer/project/cli-usage/)** — Complete command reference on the docs site.
|
|
143
|
+
- **[Troubleshooting](https://leo-gan.github.io/anonymizer/project/troubleshooting/)** — Help with common CLI problems.
|
|
144
|
+
- **[Architecture](https://leo-gan.github.io/anonymizer/project/architecture/)** — How the CLI and core work together.
|
|
@@ -117,4 +117,15 @@ pdf-anonymizer deanonymize \
|
|
|
117
117
|
data/mappings/document.mapping.json
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
This will create a deanonymized version of the file at `data/deanonymized/document.deanonymized.md`.
|
|
120
|
+
This will create a deanonymized version of the file at `data/deanonymized/document.deanonymized.md`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## See Also
|
|
125
|
+
|
|
126
|
+
- **[Main Documentation](https://leo-gan.github.io/anonymizer/)** — Full guides including the 101 course.
|
|
127
|
+
- **[Core Package README](../pdf-anonymizer-core/README.md)** — Details on the underlying library.
|
|
128
|
+
- **[Recipes & Common Workflows](https://leo-gan.github.io/anonymizer/project/recipes/)** — Practical CLI usage examples (profiles, batching, external workflows, etc.).
|
|
129
|
+
- **[CLI Reference (full)](https://leo-gan.github.io/anonymizer/project/cli-usage/)** — Complete command reference on the docs site.
|
|
130
|
+
- **[Troubleshooting](https://leo-gan.github.io/anonymizer/project/troubleshooting/)** — Help with common CLI problems.
|
|
131
|
+
- **[Architecture](https://leo-gan.github.io/anonymizer/project/architecture/)** — How the CLI and core work together.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pdf-anonymizer-cli"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.3"
|
|
4
4
|
description = "CLI for a tool to anonymize PDF, Markdown, and plain text files using LLMs."
|
|
5
5
|
authors = [{ name = "Leonid Ganeline", email = "leo.gan.57@gmail.com" }]
|
|
6
6
|
license = { text = "MIT" }
|
|
@@ -7,14 +7,14 @@ from typing import Dict, List, Optional
|
|
|
7
7
|
import typer
|
|
8
8
|
from dotenv import load_dotenv
|
|
9
9
|
from pdf_anonymizer_core.conf import (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
DEFAULT_PROMPT_NAME,
|
|
10
|
+
DEFAULT_LOG_FILE,
|
|
11
|
+
ConfigProfile,
|
|
13
12
|
PromptEnum,
|
|
14
|
-
|
|
13
|
+
get_config_for_profile,
|
|
15
14
|
get_provider_and_model_name,
|
|
16
15
|
)
|
|
17
16
|
from pdf_anonymizer_core.core import anonymize_file
|
|
17
|
+
from pdf_anonymizer_core.llm_provider import configure_cache
|
|
18
18
|
from pdf_anonymizer_core.prompts import detailed, simple
|
|
19
19
|
from pdf_anonymizer_core.utils import (
|
|
20
20
|
consolidate_mapping,
|
|
@@ -23,10 +23,11 @@ from pdf_anonymizer_core.utils import (
|
|
|
23
23
|
)
|
|
24
24
|
from typing_extensions import Annotated
|
|
25
25
|
|
|
26
|
+
# Setup logging using log file configured in conf.py
|
|
26
27
|
logging.basicConfig(
|
|
27
28
|
level=logging.INFO,
|
|
28
29
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
29
|
-
handlers=[logging.FileHandler(
|
|
30
|
+
handlers=[logging.FileHandler(DEFAULT_LOG_FILE), logging.StreamHandler()],
|
|
30
31
|
)
|
|
31
32
|
|
|
32
33
|
app = typer.Typer()
|
|
@@ -53,23 +54,34 @@ def run(
|
|
|
53
54
|
resolve_path=True,
|
|
54
55
|
),
|
|
55
56
|
],
|
|
57
|
+
config_profile: Annotated[
|
|
58
|
+
ConfigProfile,
|
|
59
|
+
typer.Option(
|
|
60
|
+
"--config-profile",
|
|
61
|
+
"-p",
|
|
62
|
+
help="The configuration profile to use (best-quality, best-speed, best-cost).",
|
|
63
|
+
case_sensitive=False,
|
|
64
|
+
),
|
|
65
|
+
] = ConfigProfile.BEST_SPEED,
|
|
56
66
|
characters_to_anonymize: Annotated[
|
|
57
|
-
int,
|
|
58
|
-
typer.Option(
|
|
59
|
-
|
|
67
|
+
Optional[int],
|
|
68
|
+
typer.Option(
|
|
69
|
+
help="Override number of characters to send for anonymization in one go (chunk size)."
|
|
70
|
+
),
|
|
71
|
+
] = None,
|
|
60
72
|
prompt_name: Annotated[
|
|
61
|
-
PromptEnum,
|
|
73
|
+
Optional[PromptEnum],
|
|
62
74
|
typer.Option(
|
|
63
|
-
help="
|
|
75
|
+
help="Override prompt template to use for anonymization.",
|
|
64
76
|
case_sensitive=False,
|
|
65
77
|
),
|
|
66
|
-
] =
|
|
78
|
+
] = None,
|
|
67
79
|
model_name: Annotated[
|
|
68
|
-
str,
|
|
80
|
+
Optional[str],
|
|
69
81
|
typer.Option(
|
|
70
|
-
help="
|
|
82
|
+
help="Override the language model to use for anonymization.",
|
|
71
83
|
),
|
|
72
|
-
] =
|
|
84
|
+
] = None,
|
|
73
85
|
anonymized_entities: Annotated[
|
|
74
86
|
Optional[Path],
|
|
75
87
|
typer.Option(
|
|
@@ -86,35 +98,45 @@ def run(
|
|
|
86
98
|
) -> None:
|
|
87
99
|
"""
|
|
88
100
|
Anonymize one or more files by replacing PII with anonymized placeholders.
|
|
89
|
-
|
|
90
|
-
Args:
|
|
91
|
-
file_paths: List of paths to files to process.
|
|
92
|
-
characters_to_anonymize: Number of characters to process in each chunk.
|
|
93
|
-
prompt_name: The prompt template to use for anonymization.
|
|
94
|
-
model_name: The language model to use for anonymization.
|
|
95
|
-
anonymized_entities: A file with a list of entities to anonymize.
|
|
96
101
|
"""
|
|
97
102
|
load_environment()
|
|
98
103
|
|
|
99
|
-
|
|
104
|
+
# Get configuration based on profile and optional user overrides
|
|
105
|
+
config = get_config_for_profile(
|
|
106
|
+
profile=config_profile,
|
|
107
|
+
model_name=model_name,
|
|
108
|
+
prompt_name=prompt_name,
|
|
109
|
+
chunk_size=characters_to_anonymize,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Configure LLM caching with values from configuration
|
|
113
|
+
configure_cache(
|
|
114
|
+
enabled=config.enable_cache,
|
|
115
|
+
cache_dir=config.cache_dir,
|
|
116
|
+
cache_file=config.cache_file,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
provider_name, _ = get_provider_and_model_name(config.model_name)
|
|
100
120
|
if provider_name == "google":
|
|
101
|
-
if "gemini" in model_name and not os.getenv("GOOGLE_API_KEY"):
|
|
121
|
+
if "gemini" in config.model_name and not os.getenv("GOOGLE_API_KEY"):
|
|
102
122
|
logging.error(
|
|
103
123
|
"Error: GOOGLE_API_KEY not found. Please set it in the .env file."
|
|
104
124
|
)
|
|
105
125
|
sys.exit(1)
|
|
106
126
|
|
|
127
|
+
logging.info(f"Using configuration profile: {config_profile.value}")
|
|
107
128
|
logging.info(f" --file-paths: {file_paths}")
|
|
108
|
-
logging.info(f" --
|
|
109
|
-
logging.info(f" --
|
|
129
|
+
logging.info(f" --chunk-size: {config.chunk_size}")
|
|
130
|
+
logging.info(f" --chunk-overlap: {config.chunk_overlap}")
|
|
131
|
+
logging.info(f" --model-name: {config.model_name}")
|
|
110
132
|
|
|
111
133
|
# Select the appropriate prompt template
|
|
112
134
|
prompt_templates: Dict[str, str] = {
|
|
113
|
-
PromptEnum.simple: simple.prompt_template,
|
|
114
|
-
PromptEnum.detailed: detailed.prompt_template,
|
|
135
|
+
PromptEnum.simple.value: simple.prompt_template,
|
|
136
|
+
PromptEnum.detailed.value: detailed.prompt_template,
|
|
115
137
|
}
|
|
116
|
-
prompt_template: str = prompt_templates[prompt_name]
|
|
117
|
-
logging.info(f" --prompt-name: {prompt_name
|
|
138
|
+
prompt_template: str = prompt_templates[config.prompt_name]
|
|
139
|
+
logging.info(f" --prompt-name: {config.prompt_name}")
|
|
118
140
|
|
|
119
141
|
entities_to_anonymize = None
|
|
120
142
|
if anonymized_entities:
|
|
@@ -128,11 +150,16 @@ def run(
|
|
|
128
150
|
logging.info("=" * 40)
|
|
129
151
|
logging.info(f"Processing file {i}/{len(file_paths)}: {file_path}")
|
|
130
152
|
full_anonymized_text, final_mapping = anonymize_file(
|
|
131
|
-
str(file_path),
|
|
132
|
-
characters_to_anonymize,
|
|
133
|
-
prompt_template,
|
|
134
|
-
model_name,
|
|
135
|
-
entities_to_anonymize,
|
|
153
|
+
file_path=str(file_path),
|
|
154
|
+
characters_to_anonymize=config.chunk_size,
|
|
155
|
+
prompt_template=prompt_template,
|
|
156
|
+
model_name=config.model_name,
|
|
157
|
+
anonymized_entities=entities_to_anonymize,
|
|
158
|
+
chunk_overlap=config.chunk_overlap,
|
|
159
|
+
regex_patterns=config.regex_patterns,
|
|
160
|
+
max_retries=config.max_retries,
|
|
161
|
+
base_retry_delay=config.base_retry_delay,
|
|
162
|
+
max_retry_delay=config.max_retry_delay,
|
|
136
163
|
)
|
|
137
164
|
|
|
138
165
|
if full_anonymized_text and final_mapping:
|
|
@@ -182,10 +209,6 @@ def deanonymize(
|
|
|
182
209
|
) -> None:
|
|
183
210
|
"""
|
|
184
211
|
Deanonymize a file using a mapping file.
|
|
185
|
-
|
|
186
|
-
Args:
|
|
187
|
-
anonymized_file: Path to the anonymized file.
|
|
188
|
-
mapping_file: Path to the mapping file.
|
|
189
212
|
"""
|
|
190
213
|
logging.info(f"Deanonymizing '{anonymized_file}' using '{mapping_file}'")
|
|
191
214
|
deanonymized_output_file, stats_file = deanonymize_file(
|
{pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pdf-anonymizer-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: CLI for a tool to anonymize PDF, Markdown, and plain text files using LLMs.
|
|
5
5
|
Author-email: Leonid Ganeline <leo.gan.57@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -131,3 +131,14 @@ pdf-anonymizer deanonymize \
|
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
This will create a deanonymized version of the file at `data/deanonymized/document.deanonymized.md`.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## See Also
|
|
138
|
+
|
|
139
|
+
- **[Main Documentation](https://leo-gan.github.io/anonymizer/)** — Full guides including the 101 course.
|
|
140
|
+
- **[Core Package README](../pdf-anonymizer-core/README.md)** — Details on the underlying library.
|
|
141
|
+
- **[Recipes & Common Workflows](https://leo-gan.github.io/anonymizer/project/recipes/)** — Practical CLI usage examples (profiles, batching, external workflows, etc.).
|
|
142
|
+
- **[CLI Reference (full)](https://leo-gan.github.io/anonymizer/project/cli-usage/)** — Complete command reference on the docs site.
|
|
143
|
+
- **[Troubleshooting](https://leo-gan.github.io/anonymizer/project/troubleshooting/)** — Help with common CLI problems.
|
|
144
|
+
- **[Architecture](https://leo-gan.github.io/anonymizer/project/architecture/)** — How the CLI and core work together.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/requires.txt
RENAMED
|
File without changes
|
{pdf_anonymizer_cli-0.3.2 → pdf_anonymizer_cli-0.3.3}/src/pdf_anonymizer_cli.egg-info/top_level.txt
RENAMED
|
File without changes
|