action0-url 0.1.0__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,99 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ # cancel superseded runs of the same branch / PR
10
+ concurrency:
11
+ group: ${{ github.workflow }}-${{ github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ checks:
16
+ name: checks (python ${{ matrix.python-version }})
17
+ runs-on: ubuntu-latest
18
+ continue-on-error: ${{ matrix.experimental }}
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
23
+ experimental: [false]
24
+ include:
25
+ # 3.15 is still a pre-release: run it, but don't fail the whole
26
+ # workflow while parts of the toolchain don't support it yet
27
+ - python-version: "3.15"
28
+ experimental: true
29
+
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+
33
+ - name: Install uv
34
+ uses: astral-sh/setup-uv@v6
35
+ with:
36
+ python-version: ${{ matrix.python-version }}
37
+
38
+ - name: Install dependencies
39
+ run: uv sync --locked
40
+
41
+ - name: ruff format
42
+ run: uv run ruff format --check
43
+
44
+ - name: ruff check
45
+ run: uv run ruff check
46
+
47
+ - name: mypy
48
+ run: uv run mypy
49
+
50
+ - name: pyright
51
+ run: uv run pyright
52
+
53
+ - name: ty
54
+ run: uv run ty check
55
+
56
+ - name: pytest
57
+ run: uv run pytest
58
+
59
+ docs:
60
+ name: docs build
61
+ runs-on: ubuntu-latest
62
+ steps:
63
+ - uses: actions/checkout@v4
64
+
65
+ - name: Install uv
66
+ uses: astral-sh/setup-uv@v6
67
+
68
+ - name: Install dependencies
69
+ run: uv sync --locked --group docs
70
+
71
+ - name: Build documentation (warnings are errors)
72
+ run: uv run --group docs sphinx-build -W --keep-going -b html docs docs/_build/html
73
+
74
+ - name: Upload pages artifact
75
+ uses: actions/upload-pages-artifact@v3
76
+ with:
77
+ path: docs/_build/html
78
+
79
+ deploy-docs:
80
+ name: deploy docs
81
+ # publish only what landed on main
82
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
83
+ needs: docs
84
+ runs-on: ubuntu-latest
85
+ permissions:
86
+ contents: read
87
+ pages: write
88
+ id-token: write
89
+ environment:
90
+ name: github-pages
91
+ url: ${{ steps.deployment.outputs.page_url }}
92
+ # the Pages site itself was enabled once via
93
+ # `gh api repos/<owner>/<repo>/pages -X POST -f build_type=workflow`;
94
+ # creating it from a workflow is impossible (GITHUB_TOKEN cannot get
95
+ # repo-administration rights)
96
+ steps:
97
+ - name: Deploy to GitHub Pages
98
+ id: deployment
99
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,62 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ build:
9
+ name: check and build
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Install uv
15
+ uses: astral-sh/setup-uv@v6
16
+
17
+ - name: Install dependencies
18
+ run: uv sync --locked
19
+
20
+ - name: Run all checks
21
+ run: |
22
+ uv run ruff format --check
23
+ uv run ruff check
24
+ uv run mypy
25
+ uv run pyright
26
+ uv run ty check
27
+ uv run pytest
28
+
29
+ - name: Check that the tag matches __version__
30
+ run: |
31
+ version=$(uv run python -c "from action0.url import __version__; print(__version__)")
32
+ if [ "v$version" != "$GITHUB_REF_NAME" ]; then
33
+ echo "tag $GITHUB_REF_NAME does not match __version__ $version" >&2
34
+ exit 1
35
+ fi
36
+
37
+ - name: Build sdist and wheel
38
+ run: uv build
39
+
40
+ - uses: actions/upload-artifact@v4
41
+ with:
42
+ name: dist
43
+ path: dist/
44
+
45
+ publish:
46
+ name: publish to PyPI
47
+ needs: build
48
+ runs-on: ubuntu-latest
49
+ environment:
50
+ name: pypi
51
+ url: https://pypi.org/p/action0-url
52
+ permissions:
53
+ # OIDC token for PyPI trusted publishing
54
+ id-token: write
55
+ steps:
56
+ - uses: actions/download-artifact@v4
57
+ with:
58
+ name: dist
59
+ path: dist/
60
+
61
+ - name: Publish to PyPI
62
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,16 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Editor files
13
+ .idea
14
+
15
+ # Sphinx build output
16
+ docs/_build/
@@ -0,0 +1 @@
1
+ 3.14
@@ -0,0 +1,52 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project
6
+
7
+ `action0-url` is a zero-dependency Python library for parsing, manipulating, and re-serializing URLs, wrapping `urllib.parse`. It ships the `action0.url` package (`action0` is a PEP 420 namespace package) from a `src/` layout, is built with hatchling, and uses `uv` for environment/dependency management.
8
+
9
+ ## Rules
10
+
11
+ - **Never commit without asking.** Also never push, tag, or publish on your own.
12
+ - **Discuss first.** Always present the plan and the intended edits and get agreement before changing files.
13
+ - Every code change comes with: tests, docstrings, inline comments where the code isn't self-explanatory, and updated usage examples in `README.md` and the Sphinx docs (`docs/usage.md`).
14
+ - Before considering work done, run ruff, mypy, and pytest (commands below) and fix what they report.
15
+ - Supported Python versions: 3.11 up to the latest release. Don't use syntax or stdlib features introduced after 3.11, and don't rely on behavior removed in newer versions.
16
+
17
+ ## Commands
18
+
19
+ `uv run` syncs the environment automatically (the dev dependency group is installed by default), so no separate install step is needed.
20
+
21
+ ```sh
22
+ uv run pytest # all tests
23
+ uv run pytest tests/action0/url/test_params.py # one file
24
+ uv run pytest tests/action0/url/test_params.py::ParamsInitTestCase::test_separator_init # one test
25
+
26
+ uv run ruff check # lint (add --fix to autofix)
27
+ uv run ruff format # format
28
+ uv run mypy # type-check (strict; files are configured in pyproject.toml)
29
+ uv run pyright # type-check
30
+ uv run ty check # type-check
31
+
32
+ uv run --group docs sphinx-build -W --keep-going -b html docs docs/_build/html # build docs
33
+
34
+ uv build # build sdist + wheel into dist/
35
+ ```
36
+
37
+ `pytest` also runs the `>>>` examples in the docstrings as doctests (`--doctest-modules` over `src/`), so docstring examples must produce their shown output exactly.
38
+
39
+ ## Architecture
40
+
41
+ Two modules under `src/action0/url/`:
42
+
43
+ - `base.py` — `Url`: parses a URL string with `urllib.parse.urlparse`, holds each part (`scheme`, `hostname`, `port`, `path`, `path_params`, `fragment`, `username`, `password`) as a plain mutable attribute, and reassembles them with `urlunparse` in `as_str()`. Constructor keyword arguments override the corresponding parts of the base URL string. `url.query` is a `Params` instance, not a string. Attributes hold percent-decoded values; `as_str()` re-encodes them (safe-character sets per part at the top of the module) and IDNA-encodes non-ASCII hostnames. Convenience API: `join()`, the `/` operator, `copy(**overrides)`, `origin()`, `normalize()` (casing, default ports, dot segments), the `authority` property, pathlib-style `parent`/`name`/`suffix`, `as_dict()`/`as_parse_result()`, `is_absolute()`/`is_relative()`, and part-wise `__eq__` (query key order ignored, per-key value order respected). `__repr__` redacts the password; `as_str()`/`str()` keep it.
44
+ - `params.py` — `Params`: an ordered multi-value mapping, internally a `list[tuple[str, str]]` of pairs so the full representation order — including values of one key interleaved with other keys — round-trips losslessly (`"a=1&b=2&a=3"` stays exactly that). It subclasses `MutableMapping`: the mapping view (`params[key]`, `get()`, `items()`, …) is single-value — the last value per key — while `get_all()`/`add()`/`as_dict()`/`as_tuples()` handle multiple values. `add()` appends at the end of the representation; `set()`/`update()` replace at the position of the key's first pair. All accepted input forms (query string, mapping, iterable of tuples, another `Params`) are normalized to the internal shape; non-string values are coerced (bools become `"true"`/`"false"`), blank values are kept (`"a="` survives round trips). `sort()` orders in place. The same class serves query parameters (`&` separator) and path params (`;` separator).
45
+
46
+ Conventions:
47
+
48
+ - The version is single-sourced as `__version__` in `src/action0/url/__init__.py`; hatch extracts it with the regex in `[tool.hatch.version]`. Bump it only there.
49
+ - Releases: pushing a `vX.Y.Z` tag triggers `.github/workflows/release.yml`, which re-runs all checks, verifies the tag matches `__version__`, builds, and publishes to PyPI via trusted publishing (environment `pypi`). Never bump the version, tag, or publish on your own — releasing is the user's call.
50
+ - Tests mirror the `src/` layout under `tests/action0/url/` and are `unittest.TestCase` classes, executed via pytest.
51
+ - Ruff enforces one import per line (isort `force-single-line`), line length 99, `action0` as first-party.
52
+ - Docs live in `docs/` (Sphinx + Furo, MyST Markdown pages, autodoc for the API reference). Docstrings are Sphinx-reST (`:param:`, `:py:meth:` roles). CI builds them with `-W` on every run and deploys to GitHub Pages on pushes to `main`. Guide examples in `docs/usage.md` show exact outputs in `#` comments — keep them truthful.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LaughInJar
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,245 @@
1
+ Metadata-Version: 2.4
2
+ Name: action0-url
3
+ Version: 0.1.0
4
+ Summary: Library for easily parsing and manipulating URLs
5
+ Project-URL: Homepage, https://github.com/LaughInJar/action0-url
6
+ Project-URL: Documentation, https://laughinjar.github.io/action0-url/
7
+ Project-URL: Source, https://github.com/LaughInJar/action0-url
8
+ Project-URL: Issues, https://github.com/LaughInJar/action0-url/issues
9
+ Author: Simon Lachinger
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: manipulation,parse,query,url,urllib
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Topic :: Internet :: WWW/HTTP
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Action0-Url
29
+
30
+ [![CI](https://github.com/LaughInJar/action0-url/actions/workflows/ci.yml/badge.svg)](https://github.com/LaughInJar/action0-url/actions/workflows/ci.yml)
31
+ [![PyPI](https://img.shields.io/pypi/v/action0-url)](https://pypi.org/project/action0-url/)
32
+
33
+ Easy URL parsing, manipulation and unparsing wrapper around
34
+ urllib.parse's methods.
35
+
36
+ Requires Python 3.11 or newer.
37
+
38
+ Full documentation including the API reference:
39
+ <https://laughinjar.github.io/action0-url/>
40
+
41
+ ## Installation
42
+
43
+ ```shell
44
+ pip install action0-url # or: uv add action0-url
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ Either with an existing url:
50
+
51
+ ```python
52
+ from action0.url import Url
53
+
54
+ url = Url("https://www.example.com/path/filename.json?foo=bar")
55
+ url.query.set("foo", "baz")
56
+ print(url.as_str())
57
+ # https://www.example.com/path/filename.json?foo=baz
58
+ url.query.add("a", "b")
59
+ print(url.as_str())
60
+ # https://www.example.com/path/filename.json?foo=baz&a=b
61
+ url.query.add("foo", "123")
62
+ print(url.as_str())
63
+ # https://www.example.com/path/filename.json?foo=baz&a=b&foo=123
64
+ url.hostname = "action0.com"
65
+ url.port = 8443
66
+ url.path = "/public/index.html"
67
+ url.username = "user"
68
+ url.password = "pass"
69
+ url.fragment = "fragment"
70
+ # instead of url.as_str() you can also use str(url) or just print(url)
71
+ print(url)
72
+ ```
73
+
74
+ Or construct one (and manipulate):
75
+
76
+ ```python
77
+ from action0.url import Url
78
+
79
+ url = Url(
80
+ scheme="https",
81
+ hostname="example.com",
82
+ path="index.html",
83
+ query={"a": "b", "foo": ["bar", "baz"]},
84
+ port=1234
85
+ )
86
+ print(url)
87
+ # https://example.com:1234/index.html?a=b&foo=bar&foo=baz
88
+ url.username="myuser"
89
+ url.port=None
90
+ print(url)
91
+ # 'https://myuser@example.com/index.html?a=b&foo=bar&foo=baz'
92
+ ```
93
+
94
+ ## Working with query parameters
95
+
96
+ `url.query` is a `Params` instance which supports single and multiple
97
+ values per parameter name. It behaves like a dict (a `MutableMapping`)
98
+ where subscription works with a single value per name — the last one —
99
+ while `add()`, `get_all()` and friends handle multiple values:
100
+
101
+ ```python
102
+ from action0.url import Url
103
+
104
+ url = Url("https://example.com/?b=2&a=1&a=3")
105
+ url.query["c"] = "4" # replace/set values, like Params.set()
106
+ url.query.add("c", ["x", 5]) # non-strings are coerced, bools become "true"/"false"
107
+ url.query.remove("a", "1")
108
+ print(url.query["a"]) # the single (last) value; use get() for a default
109
+ # 3
110
+ print(url.query.get_all("c"))
111
+ # ['4', 'x', '5']
112
+ print("b" in url.query, len(url.query))
113
+ # True 3
114
+ print(url.query.as_str())
115
+ # b=2&a=3&c=4&c=x&c=5
116
+ print(url.query.as_str(sort=True))
117
+ # a=3&b=2&c=4&c=5&c=x
118
+ url.query.update({"b": 9}, token="abc") # replaces values of existing names
119
+ print(url.query.as_str())
120
+ # b=9&a=3&c=4&c=x&c=5&token=abc
121
+ url.query.sort() # persistent, unlike as_str(sort=True)
122
+ print(url.query.as_str())
123
+ # a=3&b=9&c=4&c=5&c=x&token=abc
124
+ ```
125
+
126
+ Blank values are kept, so parsing and re-rendering is lossless:
127
+ `Params("a=&b=1").as_str()` is `"a=&b=1"` again.
128
+
129
+ `Params` can also be used on its own, e.g. with a `;` separator as used
130
+ for path parameters:
131
+
132
+ ```python
133
+ from action0.url import Params
134
+
135
+ params = Params({"foo": "bar", "a": ["b", "c"]}, separator=";")
136
+ print(params.as_str())
137
+ # foo=bar;a=b;a=c
138
+ ```
139
+
140
+ ## Building and comparing URLs
141
+
142
+ ```python
143
+ from action0.url import Url
144
+
145
+ # append path segments with "/" (always returns a new Url)
146
+ api = Url("https://example.com").origin() / "api" / "v2"
147
+ print(api / "users")
148
+ # https://example.com/api/v2/users
149
+
150
+ # resolve links like a browser does
151
+ print(Url("https://example.com/docs/intro.html").join("chapter2.html"))
152
+ # https://example.com/docs/chapter2.html
153
+
154
+ # derive variants without touching the original
155
+ url = Url("https://user:secret@example.com:8443/index.html")
156
+ print(url.copy(scheme="http", port=None))
157
+ # http://user:secret@example.com/index.html
158
+
159
+ # the authority ("hostname:port") and the origin as readable shortcuts
160
+ print(url.authority, "|", url.origin())
161
+ # example.com:8443 | https://example.com:8443
162
+
163
+ # equality compares the parts; query parameter order doesn't matter
164
+ print(Url("https://example.com?a=1&b=2") == Url("https://example.com?b=2&a=1"))
165
+ # True
166
+
167
+ # repr() never leaks the password (str() / as_str() keep it)
168
+ print(repr(url))
169
+ # Url(https://user:***@example.com:8443/index.html)
170
+ ```
171
+
172
+ ## Paths, normalization and encoding
173
+
174
+ ```python
175
+ from action0.url import Url
176
+
177
+ url = Url("https://example.com/docs/guide/intro.html?lang=en")
178
+ print(url.name, "|", url.suffix, "|", url.parent)
179
+ # intro.html | .html | https://example.com/docs/guide?lang=en
180
+ url.name = "outro.html"
181
+ print(url)
182
+ # https://example.com/docs/guide/outro.html?lang=en
183
+
184
+ # RFC 3986 style normalization: casing, default ports, dot segments
185
+ print(Url("https://example.com:443/a/./b/../c").normalize())
186
+ # https://example.com/a/c
187
+
188
+ # parts are stored decoded, rendering percent-encodes them again ...
189
+ url = Url("https://example.com/a%20b", fragment="§ 2")
190
+ print(url.path, "|", url)
191
+ # /a b | https://example.com/a%20b#%C2%A7%202
192
+
193
+ # ... and non-ASCII hostnames become punycode
194
+ print(Url(scheme="https", hostname="bücher.example"))
195
+ # https://xn--bcher-kva.example
196
+
197
+ print(url.is_absolute(), Url(path="/a").is_relative())
198
+ # True True
199
+ ```
200
+
201
+ For debugging and stdlib interoperability there are also `url.as_dict()`
202
+ (all parts as a plain dictionary) and `url.as_parse_result()` (the
203
+ `urllib.parse.ParseResult` named tuple).
204
+
205
+ ## Development
206
+
207
+ The project is managed with [uv](https://docs.astral.sh/uv/); `uv run`
208
+ creates and syncs the virtual environment automatically:
209
+
210
+ ```shell
211
+ uv run pytest # run the tests (incl. the docstring examples as doctests)
212
+ uv run ruff check # lint
213
+ uv run ruff format # format
214
+ uv run mypy # type-check (also: uv run pyright, uv run ty check)
215
+
216
+ # build the docs (Sphinx; deployed to GitHub Pages on push to main)
217
+ uv run --group docs sphinx-build -W docs docs/_build/html
218
+ ```
219
+
220
+ ### Releasing
221
+
222
+ The version lives only in `src/action0/url/__init__.py` (`__version__`).
223
+ To release: bump it, merge to `main`, then tag the release commit and push
224
+ the tag — the release workflow re-runs all checks, verifies the tag
225
+ matches `__version__`, builds sdist + wheel and publishes to PyPI via
226
+ trusted publishing:
227
+
228
+ ```shell
229
+ git tag v0.1.0
230
+ git push origin v0.1.0
231
+ ```
232
+
233
+ ## AI-assisted development
234
+
235
+ In the spirit of transparency: most of this project's code, tests and
236
+ documentation are written by [Claude Code](https://claude.com/claude-code),
237
+ Anthropic's coding agent — under human direction and review. The designs
238
+ are specified, discussed and iterated by a human, and every change is
239
+ reviewed before it lands in `main` or in a release. AI-authored commits
240
+ carry a `Co-Authored-By: Claude ...` trailer.
241
+
242
+ ## About action0
243
+
244
+ This is just the namespace I like to use for my personal projects.
245
+ I quite like namespaces.