public-source-extractor 0.1.0a2__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.
- public_source_extractor-0.1.0a2/LICENSE +22 -0
- public_source_extractor-0.1.0a2/PKG-INFO +230 -0
- public_source_extractor-0.1.0a2/README.md +206 -0
- public_source_extractor-0.1.0a2/pyproject.toml +46 -0
- public_source_extractor-0.1.0a2/setup.cfg +4 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/__init__.py +3 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/__main__.py +5 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/cli.py +61 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/errors.py +58 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/output.py +123 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/provider.py +153 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/schemas/__init__.py +0 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/schemas/output-v0.1.schema.json +90 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor/url_policy.py +170 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/PKG-INFO +230 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/SOURCES.txt +26 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/dependency_links.txt +1 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/entry_points.txt +2 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/requires.txt +5 -0
- public_source_extractor-0.1.0a2/src/public_source_extractor.egg-info/top_level.txt +1 -0
- public_source_extractor-0.1.0a2/tests/test_cli.py +117 -0
- public_source_extractor-0.1.0a2/tests/test_contract.py +80 -0
- public_source_extractor-0.1.0a2/tests/test_examples.py +29 -0
- public_source_extractor-0.1.0a2/tests/test_output.py +109 -0
- public_source_extractor-0.1.0a2/tests/test_provider.py +102 -0
- public_source_extractor-0.1.0a2/tests/test_release_metadata.py +79 -0
- public_source_extractor-0.1.0a2/tests/test_url_policy.py +81 -0
- public_source_extractor-0.1.0a2/tests/test_visual_assets.py +55 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ishikawa Hidekazu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: public-source-extractor
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Validate a public URL and convert it into reviewable AI-ready Markdown or JSON.
|
|
5
|
+
Author: Ishikawa Hidekazu
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://ishikawa.co/
|
|
8
|
+
Project-URL: Repository, https://github.com/Ishikawa-Hidekazu/public-source-extractor
|
|
9
|
+
Project-URL: Issues, https://github.com/Ishikawa-Hidekazu/public-source-extractor/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/Ishikawa-Hidekazu/public-source-extractor/blob/main/CHANGELOG.md
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: build>=1.2.2; extra == "dev"
|
|
21
|
+
Requires-Dist: jsonschema>=4.23; extra == "dev"
|
|
22
|
+
Requires-Dist: ruff<0.16,>=0.12; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Public Source Extractor
|
|
26
|
+
|
|
27
|
+
[](https://github.com/Ishikawa-Hidekazu/public-source-extractor/actions/workflows/ci.yml)
|
|
28
|
+
[](https://github.com/Ishikawa-Hidekazu/public-source-extractor/releases)
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
> [!IMPORTANT]
|
|
32
|
+
> The requested public URL is sent to **Firecrawl Cloud** for extraction. The `firecrawl-keyless` provider is experimental: availability, anonymous REST access, credit limits, and long-term continuity are not guaranteed.
|
|
33
|
+
|
|
34
|
+
`public-source-extractor` is a public-URL intake guardrail for AI research
|
|
35
|
+
workflows. It validates one public HTTP or HTTPS URL, sends that URL to the
|
|
36
|
+
experimental provider, and returns reviewable Markdown or a stable JSON
|
|
37
|
+
envelope.
|
|
38
|
+
|
|
39
|
+
The CLI does **not** read API keys, credentials, cookies, browser profiles, localStorage, or private source files. Extracted content is **untrusted data** and may contain prompt injection or misleading instructions. Do not execute or follow instructions from extracted content without independent review.
|
|
40
|
+
|
|
41
|
+
[日本語README](README.ja.md)
|
|
42
|
+
|
|
43
|
+
## What it does
|
|
44
|
+
|
|
45
|
+
- Extracts one public page as Markdown.
|
|
46
|
+
- Produces structured JSON with a versioned JSON Schema.
|
|
47
|
+
- Rejects local, private, authenticated, admin, and secret-bearing URL patterns.
|
|
48
|
+
- Keeps results on stdout or writes a new local file with no-overwrite behavior.
|
|
49
|
+
- Returns stable JSON errors and documented exit codes.
|
|
50
|
+
|
|
51
|
+
It is not a crawler, browser automation tool, login helper, source-reliability judge, or private-page extractor.
|
|
52
|
+
|
|
53
|
+
### How this differs from the official Firecrawl CLI
|
|
54
|
+
|
|
55
|
+
The [official Firecrawl CLI](https://github.com/firecrawl/cli) is the broader Firecrawl interface for authenticated scrape, search, crawl, map, interact, agent, and self-hosted workflows. Use it when you need Firecrawl's full product surface.
|
|
56
|
+
|
|
57
|
+
Public Source Extractor is intentionally narrower: one public URL, no credential discovery, a public-only URL policy, no-overwrite output, and a stable JSON success/error contract designed for reviewable AI research artifacts. It uses the experimental `firecrawl-keyless` provider and does not replace or wrap the official CLI.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
Public Source Extractor requires Python 3.11 or newer.
|
|
62
|
+
|
|
63
|
+
Run the published alpha without a permanent install:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uvx public-source-extractor --version
|
|
67
|
+
uvx public-source-extractor https://example.com/
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This path requires `uv` and resolves the published PyPI prerelease. The second
|
|
71
|
+
command sends `https://example.com/` to Firecrawl Cloud; the version command
|
|
72
|
+
does not perform extraction.
|
|
73
|
+
|
|
74
|
+
Pin the exact package version when reproducibility matters:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uvx public-source-extractor@0.1.0a2 --version
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Install the prerelease as an isolated command:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pipx install public-source-extractor==0.1.0a2
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Or use pip in an existing Python environment:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python3 -m pip install public-source-extractor==0.1.0a2
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The public Git tag remains an auditable fallback:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
uvx --from 'git+https://github.com/Ishikawa-Hidekazu/public-source-extractor.git@v0.1.0-alpha.2' public-source-extractor --version
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
PyPI publication uses GitHub Actions Trusted Publishing with short-lived OIDC
|
|
99
|
+
credentials. No long-lived PyPI API token is stored in this repository.
|
|
100
|
+
|
|
101
|
+
## Quick start
|
|
102
|
+
|
|
103
|
+
Markdown to stdout:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
public-source-extractor https://example.com/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Markdown front matter includes `provider_credits_used` and
|
|
110
|
+
`provider_elapsed_ms`. The credits field is `null` when the experimental
|
|
111
|
+
provider does not report it; elapsed time is measured by the CLI in
|
|
112
|
+
milliseconds. These are metadata-only values. Raw provider responses and
|
|
113
|
+
request identifiers are not exposed.
|
|
114
|
+
|
|
115
|
+
JSON to stdout:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
public-source-extractor https://example.com/ --mode json --pretty
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Write a new file:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
public-source-extractor https://example.com/ --output report.md
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The output path must have an existing non-symlink parent and must not already exist.
|
|
128
|
+
|
|
129
|
+
<picture>
|
|
130
|
+
<source media="(max-width: 600px)" srcset="assets/source/terminal-example-mobile.svg">
|
|
131
|
+
<img src="assets/source/terminal-example.svg" alt="Fixture-only Public Source Extractor terminal example showing one public example.com URL converted to Markdown, followed by the stable provider_rate_limited JSON error contract.">
|
|
132
|
+
</picture>
|
|
133
|
+
|
|
134
|
+
[View the public-safe examples](examples/) ·
|
|
135
|
+
[View the reproducible visual sources](assets/source/README.md)
|
|
136
|
+
|
|
137
|
+
## Real-world use
|
|
138
|
+
|
|
139
|
+
[This Japanese implementation log](https://taupe.site/entry/public-source-extractor-ai-research-cli/) shows the CLI used to turn selected public sources into reviewable Markdown and JSON artifacts. It also documents the Firecrawl Cloud boundary, untrusted extracted content, and observed provider limits.
|
|
140
|
+
|
|
141
|
+
## CLI contract
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
public-source-extractor <url> [--mode markdown|json]
|
|
145
|
+
[--output <new-path>]
|
|
146
|
+
[--timeout 1..120]
|
|
147
|
+
[--provider firecrawl-keyless]
|
|
148
|
+
[--pretty]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
| Exit | Meaning |
|
|
152
|
+
|---:|---|
|
|
153
|
+
| `0` | Success |
|
|
154
|
+
| `2` | Usage error or rejected URL |
|
|
155
|
+
| `3` | Provider, network, rate-limit, or timeout failure |
|
|
156
|
+
| `4` | Invalid, incomplete, or unsafe provider response |
|
|
157
|
+
| `5` | Output path or write failure |
|
|
158
|
+
|
|
159
|
+
On failure, stdout is empty and stderr contains exactly one JSON error object. Provider response bodies, stack traces, request IDs, and local paths are not exposed.
|
|
160
|
+
|
|
161
|
+
### Recovering from `provider_rate_limited`
|
|
162
|
+
|
|
163
|
+
The experimental provider can return HTTP 429 during short bursts or across an anonymous usage window. This is a provider availability condition, not by itself a failure of the local URL policy or parser.
|
|
164
|
+
|
|
165
|
+
When stderr reports `provider_rate_limited` with `retryable: true`:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{"schema_version":"0.1","ok":false,"error":{"code":"provider_rate_limited","message":"The experimental provider rate limit was exceeded.","retryable":true}}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The process exits with code `3` and stdout remains empty.
|
|
172
|
+
|
|
173
|
+
1. Stop the current burst instead of retrying repeatedly.
|
|
174
|
+
2. Wait and retry later. This CLI does not promise an exact delay when no retry timing is safely exposed.
|
|
175
|
+
3. Reduce request volume and process only selected public sources.
|
|
176
|
+
4. Use the original public page directly when extraction is not required.
|
|
177
|
+
|
|
178
|
+
The CLI does not automatically retry, switch providers, discover credentials, or expose raw provider bodies. See [Issue #9](https://github.com/Ishikawa-Hidekazu/public-source-extractor/issues/9) for the observed condition and documentation scope.
|
|
179
|
+
|
|
180
|
+
## Safety boundary
|
|
181
|
+
|
|
182
|
+
Before sending a URL, the CLI rejects:
|
|
183
|
+
|
|
184
|
+
- schemes other than HTTP or HTTPS;
|
|
185
|
+
- URL user information and fragments;
|
|
186
|
+
- localhost, local suffixes, and non-global literal IP addresses;
|
|
187
|
+
- ambiguous integer, octal, and hexadecimal IPv4 forms;
|
|
188
|
+
- Unicode or percent-encoded hostnames and IPv6 zone identifiers;
|
|
189
|
+
- non-default ports;
|
|
190
|
+
- login, admin, OAuth, and callback paths, including encoded forms;
|
|
191
|
+
- query parameter names that indicate tokens, secrets, passwords, credentials, signatures, sessions, cookies, authorization, or keys.
|
|
192
|
+
|
|
193
|
+
After extraction, provider redirect metadata is checked with the same public URL policy. If redirect metadata is unsafe, the result is discarded. If the provider does not supply redirect metadata, the output contains a warning.
|
|
194
|
+
|
|
195
|
+
These checks validate hostname syntax, literal IP policy, and provider-returned metadata. They cannot fully guarantee DNS rebinding behavior or the provider's actual fetch destination. Never put credentials, tokens, signed URL parameters, or other private values in a URL, even when its hostname looks public.
|
|
196
|
+
|
|
197
|
+
Firecrawl Cloud receives the requested URL and processes the page. Review [Firecrawl's terms](https://www.firecrawl.dev/terms-of-service), the target site's terms, robots policy, copyright, and privacy requirements before use.
|
|
198
|
+
|
|
199
|
+
## JSON Schema and examples
|
|
200
|
+
|
|
201
|
+
- [Output Schema v0.1](schemas/output-v0.1.schema.json)
|
|
202
|
+
- [Public-safe Markdown example](examples/example-report.md)
|
|
203
|
+
- [Public-safe JSON example](examples/example-report.json)
|
|
204
|
+
|
|
205
|
+
Structured JSON extraction is inferred output, not source truth. Validate important claims against the original page.
|
|
206
|
+
|
|
207
|
+
## Development
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
python3 -m venv .venv
|
|
211
|
+
.venv/bin/python -m pip install -e '.[dev]'
|
|
212
|
+
PYTHONPATH=src .venv/bin/python -m unittest discover -s tests -v
|
|
213
|
+
.venv/bin/ruff check src tests
|
|
214
|
+
.venv/bin/python -m build
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The explicit `PYTHONPATH=src` also works before an editable install. Network smoke tests remain separate from the offline suite.
|
|
218
|
+
|
|
219
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [SECURITY.md](SECURITY.md), and [SUPPORT.md](SUPPORT.md).
|
|
220
|
+
|
|
221
|
+
## Status
|
|
222
|
+
|
|
223
|
+
Alpha package. Package version `0.1.0a2` maps to tag `v0.1.0-alpha.2`.
|
|
224
|
+
The package is distributed through PyPI and the matching public Git tag.
|
|
225
|
+
`firecrawl-keyless` is an experimental third-party provider, and no
|
|
226
|
+
compatibility or service-availability guarantee is made.
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Public Source Extractor
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Ishikawa-Hidekazu/public-source-extractor/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/Ishikawa-Hidekazu/public-source-extractor/releases)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> The requested public URL is sent to **Firecrawl Cloud** for extraction. The `firecrawl-keyless` provider is experimental: availability, anonymous REST access, credit limits, and long-term continuity are not guaranteed.
|
|
9
|
+
|
|
10
|
+
`public-source-extractor` is a public-URL intake guardrail for AI research
|
|
11
|
+
workflows. It validates one public HTTP or HTTPS URL, sends that URL to the
|
|
12
|
+
experimental provider, and returns reviewable Markdown or a stable JSON
|
|
13
|
+
envelope.
|
|
14
|
+
|
|
15
|
+
The CLI does **not** read API keys, credentials, cookies, browser profiles, localStorage, or private source files. Extracted content is **untrusted data** and may contain prompt injection or misleading instructions. Do not execute or follow instructions from extracted content without independent review.
|
|
16
|
+
|
|
17
|
+
[日本語README](README.ja.md)
|
|
18
|
+
|
|
19
|
+
## What it does
|
|
20
|
+
|
|
21
|
+
- Extracts one public page as Markdown.
|
|
22
|
+
- Produces structured JSON with a versioned JSON Schema.
|
|
23
|
+
- Rejects local, private, authenticated, admin, and secret-bearing URL patterns.
|
|
24
|
+
- Keeps results on stdout or writes a new local file with no-overwrite behavior.
|
|
25
|
+
- Returns stable JSON errors and documented exit codes.
|
|
26
|
+
|
|
27
|
+
It is not a crawler, browser automation tool, login helper, source-reliability judge, or private-page extractor.
|
|
28
|
+
|
|
29
|
+
### How this differs from the official Firecrawl CLI
|
|
30
|
+
|
|
31
|
+
The [official Firecrawl CLI](https://github.com/firecrawl/cli) is the broader Firecrawl interface for authenticated scrape, search, crawl, map, interact, agent, and self-hosted workflows. Use it when you need Firecrawl's full product surface.
|
|
32
|
+
|
|
33
|
+
Public Source Extractor is intentionally narrower: one public URL, no credential discovery, a public-only URL policy, no-overwrite output, and a stable JSON success/error contract designed for reviewable AI research artifacts. It uses the experimental `firecrawl-keyless` provider and does not replace or wrap the official CLI.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
Public Source Extractor requires Python 3.11 or newer.
|
|
38
|
+
|
|
39
|
+
Run the published alpha without a permanent install:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uvx public-source-extractor --version
|
|
43
|
+
uvx public-source-extractor https://example.com/
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This path requires `uv` and resolves the published PyPI prerelease. The second
|
|
47
|
+
command sends `https://example.com/` to Firecrawl Cloud; the version command
|
|
48
|
+
does not perform extraction.
|
|
49
|
+
|
|
50
|
+
Pin the exact package version when reproducibility matters:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
uvx public-source-extractor@0.1.0a2 --version
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Install the prerelease as an isolated command:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pipx install public-source-extractor==0.1.0a2
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or use pip in an existing Python environment:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python3 -m pip install public-source-extractor==0.1.0a2
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The public Git tag remains an auditable fallback:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
uvx --from 'git+https://github.com/Ishikawa-Hidekazu/public-source-extractor.git@v0.1.0-alpha.2' public-source-extractor --version
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
PyPI publication uses GitHub Actions Trusted Publishing with short-lived OIDC
|
|
75
|
+
credentials. No long-lived PyPI API token is stored in this repository.
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
Markdown to stdout:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
public-source-extractor https://example.com/
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Markdown front matter includes `provider_credits_used` and
|
|
86
|
+
`provider_elapsed_ms`. The credits field is `null` when the experimental
|
|
87
|
+
provider does not report it; elapsed time is measured by the CLI in
|
|
88
|
+
milliseconds. These are metadata-only values. Raw provider responses and
|
|
89
|
+
request identifiers are not exposed.
|
|
90
|
+
|
|
91
|
+
JSON to stdout:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
public-source-extractor https://example.com/ --mode json --pretty
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Write a new file:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
public-source-extractor https://example.com/ --output report.md
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The output path must have an existing non-symlink parent and must not already exist.
|
|
104
|
+
|
|
105
|
+
<picture>
|
|
106
|
+
<source media="(max-width: 600px)" srcset="assets/source/terminal-example-mobile.svg">
|
|
107
|
+
<img src="assets/source/terminal-example.svg" alt="Fixture-only Public Source Extractor terminal example showing one public example.com URL converted to Markdown, followed by the stable provider_rate_limited JSON error contract.">
|
|
108
|
+
</picture>
|
|
109
|
+
|
|
110
|
+
[View the public-safe examples](examples/) ·
|
|
111
|
+
[View the reproducible visual sources](assets/source/README.md)
|
|
112
|
+
|
|
113
|
+
## Real-world use
|
|
114
|
+
|
|
115
|
+
[This Japanese implementation log](https://taupe.site/entry/public-source-extractor-ai-research-cli/) shows the CLI used to turn selected public sources into reviewable Markdown and JSON artifacts. It also documents the Firecrawl Cloud boundary, untrusted extracted content, and observed provider limits.
|
|
116
|
+
|
|
117
|
+
## CLI contract
|
|
118
|
+
|
|
119
|
+
```text
|
|
120
|
+
public-source-extractor <url> [--mode markdown|json]
|
|
121
|
+
[--output <new-path>]
|
|
122
|
+
[--timeout 1..120]
|
|
123
|
+
[--provider firecrawl-keyless]
|
|
124
|
+
[--pretty]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| Exit | Meaning |
|
|
128
|
+
|---:|---|
|
|
129
|
+
| `0` | Success |
|
|
130
|
+
| `2` | Usage error or rejected URL |
|
|
131
|
+
| `3` | Provider, network, rate-limit, or timeout failure |
|
|
132
|
+
| `4` | Invalid, incomplete, or unsafe provider response |
|
|
133
|
+
| `5` | Output path or write failure |
|
|
134
|
+
|
|
135
|
+
On failure, stdout is empty and stderr contains exactly one JSON error object. Provider response bodies, stack traces, request IDs, and local paths are not exposed.
|
|
136
|
+
|
|
137
|
+
### Recovering from `provider_rate_limited`
|
|
138
|
+
|
|
139
|
+
The experimental provider can return HTTP 429 during short bursts or across an anonymous usage window. This is a provider availability condition, not by itself a failure of the local URL policy or parser.
|
|
140
|
+
|
|
141
|
+
When stderr reports `provider_rate_limited` with `retryable: true`:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{"schema_version":"0.1","ok":false,"error":{"code":"provider_rate_limited","message":"The experimental provider rate limit was exceeded.","retryable":true}}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The process exits with code `3` and stdout remains empty.
|
|
148
|
+
|
|
149
|
+
1. Stop the current burst instead of retrying repeatedly.
|
|
150
|
+
2. Wait and retry later. This CLI does not promise an exact delay when no retry timing is safely exposed.
|
|
151
|
+
3. Reduce request volume and process only selected public sources.
|
|
152
|
+
4. Use the original public page directly when extraction is not required.
|
|
153
|
+
|
|
154
|
+
The CLI does not automatically retry, switch providers, discover credentials, or expose raw provider bodies. See [Issue #9](https://github.com/Ishikawa-Hidekazu/public-source-extractor/issues/9) for the observed condition and documentation scope.
|
|
155
|
+
|
|
156
|
+
## Safety boundary
|
|
157
|
+
|
|
158
|
+
Before sending a URL, the CLI rejects:
|
|
159
|
+
|
|
160
|
+
- schemes other than HTTP or HTTPS;
|
|
161
|
+
- URL user information and fragments;
|
|
162
|
+
- localhost, local suffixes, and non-global literal IP addresses;
|
|
163
|
+
- ambiguous integer, octal, and hexadecimal IPv4 forms;
|
|
164
|
+
- Unicode or percent-encoded hostnames and IPv6 zone identifiers;
|
|
165
|
+
- non-default ports;
|
|
166
|
+
- login, admin, OAuth, and callback paths, including encoded forms;
|
|
167
|
+
- query parameter names that indicate tokens, secrets, passwords, credentials, signatures, sessions, cookies, authorization, or keys.
|
|
168
|
+
|
|
169
|
+
After extraction, provider redirect metadata is checked with the same public URL policy. If redirect metadata is unsafe, the result is discarded. If the provider does not supply redirect metadata, the output contains a warning.
|
|
170
|
+
|
|
171
|
+
These checks validate hostname syntax, literal IP policy, and provider-returned metadata. They cannot fully guarantee DNS rebinding behavior or the provider's actual fetch destination. Never put credentials, tokens, signed URL parameters, or other private values in a URL, even when its hostname looks public.
|
|
172
|
+
|
|
173
|
+
Firecrawl Cloud receives the requested URL and processes the page. Review [Firecrawl's terms](https://www.firecrawl.dev/terms-of-service), the target site's terms, robots policy, copyright, and privacy requirements before use.
|
|
174
|
+
|
|
175
|
+
## JSON Schema and examples
|
|
176
|
+
|
|
177
|
+
- [Output Schema v0.1](schemas/output-v0.1.schema.json)
|
|
178
|
+
- [Public-safe Markdown example](examples/example-report.md)
|
|
179
|
+
- [Public-safe JSON example](examples/example-report.json)
|
|
180
|
+
|
|
181
|
+
Structured JSON extraction is inferred output, not source truth. Validate important claims against the original page.
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
python3 -m venv .venv
|
|
187
|
+
.venv/bin/python -m pip install -e '.[dev]'
|
|
188
|
+
PYTHONPATH=src .venv/bin/python -m unittest discover -s tests -v
|
|
189
|
+
.venv/bin/ruff check src tests
|
|
190
|
+
.venv/bin/python -m build
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The explicit `PYTHONPATH=src` also works before an editable install. Network smoke tests remain separate from the offline suite.
|
|
194
|
+
|
|
195
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [SECURITY.md](SECURITY.md), and [SUPPORT.md](SUPPORT.md).
|
|
196
|
+
|
|
197
|
+
## Status
|
|
198
|
+
|
|
199
|
+
Alpha package. Package version `0.1.0a2` maps to tag `v0.1.0-alpha.2`.
|
|
200
|
+
The package is distributed through PyPI and the matching public Git tag.
|
|
201
|
+
`firecrawl-keyless` is an experimental third-party provider, and no
|
|
202
|
+
compatibility or service-availability guarantee is made.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "public-source-extractor"
|
|
7
|
+
version = "0.1.0a2"
|
|
8
|
+
description = "Validate a public URL and convert it into reviewable AI-ready Markdown or JSON."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "Ishikawa Hidekazu"}]
|
|
13
|
+
dependencies = []
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://ishikawa.co/"
|
|
24
|
+
Repository = "https://github.com/Ishikawa-Hidekazu/public-source-extractor"
|
|
25
|
+
Issues = "https://github.com/Ishikawa-Hidekazu/public-source-extractor/issues"
|
|
26
|
+
Changelog = "https://github.com/Ishikawa-Hidekazu/public-source-extractor/blob/main/CHANGELOG.md"
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = [
|
|
30
|
+
"build>=1.2.2",
|
|
31
|
+
"jsonschema>=4.23",
|
|
32
|
+
"ruff>=0.12,<0.16",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
public-source-extractor = "public_source_extractor.cli:main"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
public_source_extractor = ["schemas/*.json"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools]
|
|
42
|
+
include-package-data = true
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
target-version = "py311"
|
|
46
|
+
line-length = 100
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Sequence
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .errors import ExtractorError, InputRejected
|
|
11
|
+
from .output import build_success_envelope, render_json, render_markdown, write_new_file_atomic
|
|
12
|
+
from .provider import FirecrawlKeylessProvider
|
|
13
|
+
from .url_policy import validate_public_url
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class StableArgumentParser(argparse.ArgumentParser):
|
|
17
|
+
def error(self, _message: str) -> None:
|
|
18
|
+
raise InputRejected()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
22
|
+
parser = StableArgumentParser(
|
|
23
|
+
prog="public-source-extractor",
|
|
24
|
+
description="Convert one public URL into Markdown or a stable JSON envelope.",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument("url", help="Public HTTP or HTTPS URL.")
|
|
27
|
+
parser.add_argument("--mode", choices=("markdown", "json"), default="markdown")
|
|
28
|
+
parser.add_argument("--output", type=Path, help="Write to a new file instead of stdout.")
|
|
29
|
+
parser.add_argument("--timeout", type=int, default=60, metavar="SECONDS")
|
|
30
|
+
parser.add_argument("--provider", choices=("firecrawl-keyless",), default="firecrawl-keyless")
|
|
31
|
+
parser.add_argument("--pretty", action="store_true", help="Pretty-print JSON output.")
|
|
32
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
33
|
+
return parser
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run(argv: Sequence[str] | None = None) -> int:
|
|
37
|
+
try:
|
|
38
|
+
args = build_parser().parse_args(argv)
|
|
39
|
+
if not 1 <= args.timeout <= 120:
|
|
40
|
+
raise InputRejected()
|
|
41
|
+
validate_public_url(args.url)
|
|
42
|
+
provider = FirecrawlKeylessProvider()
|
|
43
|
+
result = provider.extract(args.url, args.mode, args.timeout)
|
|
44
|
+
envelope = build_success_envelope(args.url, args.mode, result)
|
|
45
|
+
rendered = (
|
|
46
|
+
render_markdown(envelope)
|
|
47
|
+
if args.mode == "markdown"
|
|
48
|
+
else render_json(envelope, args.pretty)
|
|
49
|
+
)
|
|
50
|
+
if args.output is None:
|
|
51
|
+
sys.stdout.write(rendered)
|
|
52
|
+
else:
|
|
53
|
+
write_new_file_atomic(args.output, rendered)
|
|
54
|
+
return 0
|
|
55
|
+
except ExtractorError as exc:
|
|
56
|
+
sys.stderr.write(json.dumps(exc.envelope(), ensure_ascii=False) + "\n")
|
|
57
|
+
return exc.exit_code
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def main() -> int:
|
|
61
|
+
return run()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ExtractorError(Exception):
|
|
5
|
+
code = "extractor_error"
|
|
6
|
+
exit_code = 1
|
|
7
|
+
retryable = False
|
|
8
|
+
public_message = "Extraction failed."
|
|
9
|
+
|
|
10
|
+
def __init__(self, message: str | None = None) -> None:
|
|
11
|
+
super().__init__(message or self.public_message)
|
|
12
|
+
|
|
13
|
+
def envelope(self) -> dict[str, object]:
|
|
14
|
+
return {
|
|
15
|
+
"schema_version": "0.1",
|
|
16
|
+
"ok": False,
|
|
17
|
+
"error": {
|
|
18
|
+
"code": self.code,
|
|
19
|
+
"message": self.public_message,
|
|
20
|
+
"retryable": self.retryable,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class InputRejected(ExtractorError):
|
|
26
|
+
code = "input_rejected"
|
|
27
|
+
exit_code = 2
|
|
28
|
+
public_message = "The URL was rejected by the public-source safety policy."
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ProviderFailure(ExtractorError):
|
|
32
|
+
code = "provider_failure"
|
|
33
|
+
exit_code = 3
|
|
34
|
+
retryable = True
|
|
35
|
+
public_message = "The extraction provider is unavailable or rejected the request."
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ProviderRateLimited(ProviderFailure):
|
|
39
|
+
code = "provider_rate_limited"
|
|
40
|
+
public_message = "The experimental provider rate limit was exceeded."
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ProviderTimeout(ProviderFailure):
|
|
44
|
+
code = "provider_timeout"
|
|
45
|
+
public_message = "The extraction provider timed out."
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class InvalidProviderResponse(ExtractorError):
|
|
49
|
+
code = "invalid_provider_response"
|
|
50
|
+
exit_code = 4
|
|
51
|
+
public_message = "The extraction provider returned an invalid or unsafe response."
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class OutputFailure(ExtractorError):
|
|
55
|
+
code = "output_failure"
|
|
56
|
+
exit_code = 5
|
|
57
|
+
public_message = "The output file could not be written safely."
|
|
58
|
+
|