fetchurl-sdk 0.2.0__tar.gz → 0.2.2__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.
@@ -0,0 +1,76 @@
1
+ name: Autorelease
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+ inputs:
10
+ new_version:
11
+ description: "Version bump mode (svu) or explicit x.y.z"
12
+ type: choice
13
+ default: next
14
+ options: [next, patch, minor, major]
15
+
16
+ jobs:
17
+ autorelease:
18
+ runs-on: ubuntu-latest
19
+ permissions:
20
+ contents: write
21
+ id-token: write
22
+ steps:
23
+ - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - name: Setup git config
28
+ run: |
29
+ git config user.name actions-bot
30
+ git config user.email actions-bot@users.noreply.github.com
31
+
32
+ - uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3
33
+
34
+ - name: Sync deps
35
+ run: uv sync --extra test
36
+
37
+ - name: Unit tests
38
+ run: uv run python -m unittest test_fetchurl.py
39
+
40
+ - name: Integration tests (optional)
41
+ if: vars.FETCHURL_TEST_IMAGE != ''
42
+ env:
43
+ FETCHURL_TEST_IMAGE: ${{ vars.FETCHURL_TEST_IMAGE }}
44
+ run: uv run --extra test python -m unittest test_fetchurl_integration.py
45
+ continue-on-error: true
46
+
47
+ - name: Prepare release (svu, commit, local tag)
48
+ if: github.event_name == 'workflow_dispatch'
49
+ env:
50
+ NEW_VERSION: ${{ github.event.inputs.new_version }}
51
+ run: |
52
+ VERSION="$(./make_release prepare "$NEW_VERSION")"
53
+ echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
54
+ echo "Prepared $VERSION (not pushed until publish succeeds)" >> "$GITHUB_STEP_SUMMARY"
55
+
56
+ - name: Build
57
+ if: env.RELEASE_VERSION != ''
58
+ run: uv build
59
+
60
+ - name: Publish to PyPI
61
+ if: env.RELEASE_VERSION != ''
62
+ env:
63
+ UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
64
+ run: |
65
+ if [[ -z "${UV_PUBLISH_TOKEN:-}" ]]; then
66
+ echo "PYPI_TOKEN not set; trying trusted publishing (OIDC)..."
67
+ uv publish
68
+ else
69
+ uv publish --token "$UV_PUBLISH_TOKEN"
70
+ fi
71
+
72
+ - name: Push commit, tag, and GitHub release
73
+ if: env.RELEASE_VERSION != ''
74
+ env:
75
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
+ run: ./make_release push "$RELEASE_VERSION"
@@ -0,0 +1 @@
1
+ __pycache__/
@@ -0,0 +1,2 @@
1
+ tag.prefix: ""
2
+ v0: true
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Eduardo
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.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: fetchurl-sdk
3
+ Version: 0.2.2
4
+ Summary: Protocol-level client SDK for fetchurl content-addressable cache servers
5
+ Project-URL: Homepage, https://pypi.org/project/fetchurl-sdk/
6
+ Project-URL: Repository, https://github.com/fetchurl/sdk-python
7
+ Project-URL: Bug Tracker, https://github.com/fetchurl/sdk-python/issues
8
+ Author: lucasew
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: cache,content-addressable,fetchurl,hash,sha256
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Internet :: WWW/HTTP
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.8
19
+ Provides-Extra: test
20
+ Requires-Dist: httpx>=0.27.0; extra == 'test'
21
+ Requires-Dist: testcontainers>=3.7.0; extra == 'test'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # fetchurl Python SDK
25
+
26
+ Protocol-level client for [fetchurl](https://github.com/fetchurl/spec) content-addressable cache servers.
27
+
28
+ Zero runtime dependencies — uses only the Python standard library. Works with any HTTP library via `Fetcher` / `AsyncFetcher` protocols.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install fetchurl-sdk
34
+ # or
35
+ uv add fetchurl-sdk
36
+ ```
37
+
38
+ ## Protocol
39
+
40
+ Normative behavior: **[fetchurl/spec](https://github.com/fetchurl/spec)** (`SPEC.md`).
41
+
42
+ Reference server: **[fetchurl/fetchurl](https://github.com/fetchurl/fetchurl)**.
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ from fetchurl import fetch, UrllibFetcher, parse_fetchurl_server
48
+ import os
49
+
50
+ servers = parse_fetchurl_server(os.environ.get("FETCHURL_SERVER", ""))
51
+ # Or drive FetchSession yourself with your HTTP client — see package docstring.
52
+ ```
53
+
54
+ Clients **must** treat the server as untrusted and verify the hash (this SDK does that for you).
55
+
56
+ ## Environment
57
+
58
+ | Variable | Meaning |
59
+ |----------|---------|
60
+ | `FETCHURL_SERVER` | Server base URL(s) per the [spec](https://github.com/fetchurl/spec/blob/main/SPEC.md). Empty/absent disables server use. |
61
+
62
+ ## Development
63
+
64
+ ```bash
65
+ uv sync --dev
66
+ uv run python -m unittest test_fetchurl.py
67
+ # Integration (Docker + image):
68
+ # FETCHURL_TEST_IMAGE=fetchurl:local uv run --extra test python -m unittest test_fetchurl_integration.py
69
+ ```
70
+
71
+ ## Related
72
+
73
+ | Repo | Role |
74
+ |------|------|
75
+ | [fetchurl/spec](https://github.com/fetchurl/spec) | Protocol |
76
+ | [fetchurl/fetchurl](https://github.com/fetchurl/fetchurl) | Go server |
77
+ | [fetchurl/sdk-js](https://github.com/fetchurl/sdk-js) | JavaScript SDK |
78
+ | [fetchurl/sdk-rust](https://github.com/fetchurl/sdk-rust) | Rust SDK |
@@ -0,0 +1,55 @@
1
+ # fetchurl Python SDK
2
+
3
+ Protocol-level client for [fetchurl](https://github.com/fetchurl/spec) content-addressable cache servers.
4
+
5
+ Zero runtime dependencies — uses only the Python standard library. Works with any HTTP library via `Fetcher` / `AsyncFetcher` protocols.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install fetchurl-sdk
11
+ # or
12
+ uv add fetchurl-sdk
13
+ ```
14
+
15
+ ## Protocol
16
+
17
+ Normative behavior: **[fetchurl/spec](https://github.com/fetchurl/spec)** (`SPEC.md`).
18
+
19
+ Reference server: **[fetchurl/fetchurl](https://github.com/fetchurl/fetchurl)**.
20
+
21
+ ## Usage
22
+
23
+ ```python
24
+ from fetchurl import fetch, UrllibFetcher, parse_fetchurl_server
25
+ import os
26
+
27
+ servers = parse_fetchurl_server(os.environ.get("FETCHURL_SERVER", ""))
28
+ # Or drive FetchSession yourself with your HTTP client — see package docstring.
29
+ ```
30
+
31
+ Clients **must** treat the server as untrusted and verify the hash (this SDK does that for you).
32
+
33
+ ## Environment
34
+
35
+ | Variable | Meaning |
36
+ |----------|---------|
37
+ | `FETCHURL_SERVER` | Server base URL(s) per the [spec](https://github.com/fetchurl/spec/blob/main/SPEC.md). Empty/absent disables server use. |
38
+
39
+ ## Development
40
+
41
+ ```bash
42
+ uv sync --dev
43
+ uv run python -m unittest test_fetchurl.py
44
+ # Integration (Docker + image):
45
+ # FETCHURL_TEST_IMAGE=fetchurl:local uv run --extra test python -m unittest test_fetchurl_integration.py
46
+ ```
47
+
48
+ ## Related
49
+
50
+ | Repo | Role |
51
+ |------|------|
52
+ | [fetchurl/spec](https://github.com/fetchurl/spec) | Protocol |
53
+ | [fetchurl/fetchurl](https://github.com/fetchurl/fetchurl) | Go server |
54
+ | [fetchurl/sdk-js](https://github.com/fetchurl/sdk-js) | JavaScript SDK |
55
+ | [fetchurl/sdk-rust](https://github.com/fetchurl/sdk-rust) | Rust SDK |
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env -S python3 -u
2
+ """Bump version (svu), commit + tag locally. Push only via `push` after publish succeeds."""
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import re
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ ROOT = Path(__file__).resolve().parent
12
+ MANIFEST = ROOT / "pyproject.toml"
13
+ MANIFEST_PATHS = [str(MANIFEST.relative_to(ROOT))]
14
+ SVU_MODES = frozenset({"next", "major", "minor", "patch"})
15
+ UPLOAD_GLOB: str | None = None
16
+ VERSION_RE = re.compile(r'^version\s*=\s*"[^"]*"', re.M)
17
+
18
+
19
+ def log(msg: str) -> None:
20
+ print(msg, file=sys.stderr)
21
+
22
+
23
+ def run(cmd: list[str], *, check: bool = True, capture: bool = False) -> subprocess.CompletedProcess:
24
+ return subprocess.run(cmd, cwd=ROOT, check=check, text=True, capture_output=capture)
25
+
26
+
27
+ def run_out(cmd: list[str]) -> str:
28
+ return run(cmd, capture=True).stdout.strip()
29
+
30
+
31
+ def resolve_version(mode: str) -> str:
32
+ mode = mode.lstrip("v")
33
+ if mode in SVU_MODES:
34
+ return run_out(["svu", mode]).lstrip("v")
35
+ return mode
36
+
37
+
38
+ def write_manifest(version: str) -> None:
39
+ text = MANIFEST.read_text(encoding="utf-8")
40
+ if not VERSION_RE.search(text):
41
+ raise SystemExit('version = "..." not found in pyproject.toml')
42
+ MANIFEST.write_text(VERSION_RE.sub(f'version = "{version}"', text, count=1), encoding="utf-8")
43
+
44
+
45
+ def read_manifest_version() -> str:
46
+ m = re.search(r'^version\s*=\s*"([^"]+)"', MANIFEST.read_text(encoding="utf-8"), re.M)
47
+ if not m:
48
+ raise SystemExit("could not read version from pyproject.toml")
49
+ return m.group(1)
50
+
51
+ def git_commit_and_tag(version: str, paths: list[str]) -> None:
52
+ # Never let git write to stdout — CI captures only the version line from prepare.
53
+ if paths:
54
+ run(["git", "add", *paths], capture=True)
55
+ else:
56
+ run(["git", "add", "-A"], capture=True)
57
+ staged = run(["git", "diff", "--cached", "--quiet"], check=False, capture=True)
58
+ if staged.returncode != 0:
59
+ cp = run(["git", "commit", "-sm", f"bump to {version}"], capture=True)
60
+ if cp.stdout:
61
+ log(cp.stdout.rstrip())
62
+ if cp.stderr:
63
+ log(cp.stderr.rstrip())
64
+ else:
65
+ log("nothing to commit (manifest unchanged?)")
66
+ exists = run(["git", "rev-parse", "-q", "--verify", f"refs/tags/{version}"], check=False, capture=True)
67
+ if exists.returncode == 0:
68
+ run(["git", "tag", "-f", version], capture=True)
69
+ log(f"moved local tag {version}")
70
+ else:
71
+ run(["git", "tag", version], capture=True)
72
+ log(f"created local tag {version}")
73
+
74
+
75
+ def push_release(version: str, *, upload_glob: str | None = None) -> None:
76
+ """Push branch + tag and create GitHub release. Call only after registry publish succeeds."""
77
+ branch = run_out(["git", "rev-parse", "--abbrev-ref", "HEAD"])
78
+ for cmd in (
79
+ ["git", "push", "origin", f"HEAD:{branch}"],
80
+ ["git", "push", "origin", version],
81
+ ):
82
+ cp = run(cmd, capture=True)
83
+ if cp.stdout:
84
+ log(cp.stdout.rstrip())
85
+ if cp.stderr:
86
+ log(cp.stderr.rstrip())
87
+ chk = run(["gh", "release", "view", version], check=False, capture=True)
88
+ if chk.returncode == 0:
89
+ log(f"GitHub release {version} already exists")
90
+ else:
91
+ cp = run(
92
+ [
93
+ "gh",
94
+ "release",
95
+ "create",
96
+ version,
97
+ "--title",
98
+ f"Release {version}",
99
+ "--generate-notes",
100
+ ],
101
+ capture=True,
102
+ )
103
+ if cp.stdout:
104
+ log(cp.stdout.rstrip())
105
+ if cp.stderr:
106
+ log(cp.stderr.rstrip())
107
+ if upload_glob:
108
+ paths = sorted(ROOT.glob(upload_glob))
109
+ if paths:
110
+ cp = run(
111
+ ["gh", "release", "upload", version, *[str(p) for p in paths], "--clobber"],
112
+ capture=True,
113
+ )
114
+ if cp.stdout:
115
+ log(cp.stdout.rstrip())
116
+ if cp.stderr:
117
+ log(cp.stderr.rstrip())
118
+ log(f"pushed commit + tag + release {version}")
119
+
120
+
121
+ def build_parser() -> argparse.ArgumentParser:
122
+ p = argparse.ArgumentParser(
123
+ prog="./make_release",
124
+ description=(
125
+ "Bump version with svu, commit and tag locally. "
126
+ "Push commit/tag/GitHub release only via the push subcommand "
127
+ "(run after a successful registry publish)."
128
+ ),
129
+ )
130
+ sub = p.add_subparsers(dest="command", required=True)
131
+
132
+ prep = sub.add_parser(
133
+ "prepare",
134
+ help="svu → write manifest → local commit + local tag (no remote push)",
135
+ )
136
+ prep.add_argument(
137
+ "mode",
138
+ nargs="?",
139
+ default="next",
140
+ help="svu mode (next|major|minor|patch) or explicit x.y.z (default: next)",
141
+ )
142
+
143
+ push_p = sub.add_parser(
144
+ "push",
145
+ help="push branch + tag and create GitHub release (after successful publish)",
146
+ )
147
+ push_p.add_argument(
148
+ "version",
149
+ nargs="?",
150
+ default=None,
151
+ help="semver to push (default: version from manifest)",
152
+ )
153
+
154
+ for mode in sorted(SVU_MODES):
155
+ sp = sub.add_parser(mode, help=f"shorthand for: prepare {mode}")
156
+ sp.set_defaults(command="prepare", mode=mode)
157
+
158
+ return p
159
+
160
+
161
+ def main(argv: list[str] | None = None) -> int:
162
+ parser = build_parser()
163
+ args_list = list(sys.argv[1:] if argv is None else argv)
164
+ # Bare semver → prepare <semver>
165
+ if (
166
+ args_list
167
+ and args_list[0] not in ("prepare", "push", "-h", "--help")
168
+ and args_list[0] not in SVU_MODES
169
+ and re.fullmatch(r"v?\d+\.\d+\.\d+", args_list[0])
170
+ ):
171
+ args_list = ["prepare", args_list[0].lstrip("v"), *args_list[1:]]
172
+
173
+ args = parser.parse_args(args_list)
174
+
175
+ if args.command == "prepare":
176
+ version = resolve_version(args.mode)
177
+ write_manifest(version)
178
+ git_commit_and_tag(version, MANIFEST_PATHS)
179
+ print(version)
180
+ return 0
181
+
182
+ if args.command == "push":
183
+ version = (args.version or read_manifest_version()).lstrip("v")
184
+ push_release(version, upload_glob=UPLOAD_GLOB)
185
+ print(version)
186
+ return 0
187
+
188
+ parser.error(f"unknown command {args.command!r}")
189
+ return 2
190
+
191
+
192
+ if __name__ == "__main__":
193
+ sys.exit(main())
@@ -1,3 +1,4 @@
1
1
  [tools]
2
2
  ruff = "0.14.13"
3
+ svu = "3.3.0"
3
4
  uv = "0.9.28"
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "fetchurl-sdk"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Protocol-level client SDK for fetchurl content-addressable cache servers"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -22,9 +22,9 @@ classifiers = [
22
22
  ]
23
23
 
24
24
  [project.urls]
25
- Homepage = "https://github.com/lucasew/fetchurl"
26
- Repository = "https://github.com/lucasew/fetchurl"
27
- "Bug Tracker" = "https://github.com/lucasew/fetchurl/issues"
25
+ Homepage = "https://pypi.org/project/fetchurl-sdk/"
26
+ Repository = "https://github.com/fetchurl/sdk-python"
27
+ "Bug Tracker" = "https://github.com/fetchurl/sdk-python/issues"
28
28
 
29
29
  [project.optional-dependencies]
30
30
  test = ["testcontainers>=3.7.0", "httpx>=0.27.0"]
@@ -57,6 +57,7 @@ class TestIntegration(unittest.TestCase):
57
57
  DockerContainer(image_ref)
58
58
  .with_command("server")
59
59
  .with_network(net)
60
+ .with_env("FETCHURL_ALLOW_PRIVATE_IPS", "1")
60
61
  .with_exposed_ports(8080)
61
62
  ).start()
62
63
 
@@ -237,7 +237,7 @@ wheels = [
237
237
 
238
238
  [[package]]
239
239
  name = "fetchurl-sdk"
240
- version = "0.1.0"
240
+ version = "0.2.1"
241
241
  source = { editable = "." }
242
242
 
243
243
  [package.optional-dependencies]
@@ -1,2 +0,0 @@
1
- .venv
2
- __pycache__
@@ -1 +0,0 @@
1
- 3.13
@@ -1,25 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: fetchurl-sdk
3
- Version: 0.2.0
4
- Summary: Protocol-level client SDK for fetchurl content-addressable cache servers
5
- Project-URL: Homepage, https://github.com/lucasew/fetchurl
6
- Project-URL: Repository, https://github.com/lucasew/fetchurl
7
- Project-URL: Bug Tracker, https://github.com/lucasew/fetchurl/issues
8
- Author: lucasew
9
- License: MIT
10
- Keywords: cache,content-addressable,fetchurl,hash,sha256
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Topic :: Internet :: WWW/HTTP
16
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Requires-Python: >=3.8
18
- Provides-Extra: test
19
- Requires-Dist: httpx>=0.27.0; extra == 'test'
20
- Requires-Dist: testcontainers>=3.7.0; extra == 'test'
21
- Description-Content-Type: text/markdown
22
-
23
- # fetchurl
24
-
25
- Simple caching server for URLs with a hash.
@@ -1,3 +0,0 @@
1
- # fetchurl
2
-
3
- Simple caching server for URLs with a hash.