Skip to content

feat(python): add PMTiles archive helper - #870

Merged
giswqs merged 1 commit into
opengeos:mainfrom
choupeanut:fix/557-python-pmtiles
Oct 25, 2026
Merged

giswqs merged 1 commit into
opengeos:mainfrom
choupeanut:fix/557-python-pmtiles

Conversation

@choupeanut

@choupeanut choupeanut commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Python currently needs raw map.addTiles calls to add a PMTiles archive. Add Session.add_pmtiles and Map.add_pmtiles for PMTiles archives by URL or local path. The shared helper uses map.addTiles, maps source_layers and style to its existing parameters, and preserves the notebook's project synchronization. No dependency, engine command or project-format changes.

The shared tile archive style resolver also honors explicitly selected source layers, reusing the existing named-layer style generator. Previously the setting was saved but ignored in favor of archive metadata or the basemap guess. Custom styles retain precedence, as they do for vector tile templates.

Document the helper and the existing notebook limitation: a local archive is not embedded in the browser, so use a browser-accessible URL there.

Testing

  • Built and installed the current Python package with maturin; all 33 Python tests pass with notebook and GeoPandas dependencies installed.

  • New offline regressions cover extensionless URLs, source layers, structured/JSON-text styles, project reopening, a generated local archive passed as a Path, default naming, archive bounds, undo, rejected styles and notebook project synchronization.

  • All 168 tiles library tests pass. The new archive-style regression fails on the unmodified resolver (32 basemap style layers instead of the chosen layer's 3), and passes with the fix; it also covers explicitly chosen basemap-like names and custom-style precedence.

  • cargo xtask ci: formatting, Clippy with warnings denied, 2,176 tests passed (16 ignored), and layers: ok.

  • uvx pre-commit run --all-files.

  • cargo build --locked --target wasm32-unknown-unknown -p rustgis-web.

Local validation uses Linux and Python 3.12; Windows, macOS and live browser rendering were not exercised locally.

Related issue

Part of #557: the Python item only. The tracking issue's remaining PMTiles parity items stay open.

Summary by CodeRabbit

  • New Features

    • Added support for adding raster and vector PMTiles archives from a web address or local path in Python maps and sessions. Options include naming the archive, selecting vector source layers, providing a custom style, and setting tile parameters.
    • Vector archives can now use explicitly selected source layers when no custom style is supplied, instead of relying on archive metadata or an automatic basemap guess.
    • Added a PMTiles example to the Jupyter map.
  • Documentation

    • Documented PMTiles setup, styling options, and requirements for displaying web-hosted and local archives.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 70b9bc9f-132b-4a0d-9ea7-1dba01638aa2
Commits

Reviewing files that changed from the base of the PR and between 9003276 and 8526c27.

Files selected for processing: 6
  • apps/rustgis-python/README.md
  • apps/rustgis-python/python/rustgis/__init__.py
  • apps/rustgis-python/tests/test_session.py
  • apps/rustgis-python/tests/test_widget.py
  • crates/tiles/src/source.rs
  • docs/python.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The Python API now adds raster or vector PMTiles archives from a URL or path. Vector archives can use explicitly selected source layers or a custom style. Tests cover project persistence, validation, bounds, undo, and widget updates. The Python documentation and Jupyter example describe the new API.

Changes: PMTiles archive support

Layer / File(s) Summary
Explicit archive layer styling
crates/tiles/src/source.rs
archive_style now generates layers for explicitly selected vector source layers after checking for a custom style. Tests cover generated fill, line, and point layers, and custom-style precedence.
Python PMTiles API and coverage
apps/rustgis-python/python/rustgis/__init__.py, apps/rustgis-python/tests/*, apps/rustgis-python/README.md, docs/python.md
add_pmtiles accepts a URL or path and optional source layers, style, and tile parameters. Tests cover serialization, local archive bounds, undo, invalid styles, and widget updates. The example and documentation describe PMTiles usage and requirements.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant PythonAPI as _Api.add_pmtiles
  participant MapTiles as map.addTiles
  participant ArchiveStyle as archive_style
  Caller->>PythonAPI: add PMTiles URL or path
  PythonAPI->>MapTiles: forward PMTiles kind and optional style parameters
  MapTiles->>ArchiveStyle: provide archive style specification
  ArchiveStyle->>MapTiles: return selected or generated style
Loading

Suggested reviewers: giswqs

Merge Risk: Minimal · up to 8526c

No specific issue remains that calls for a fix before merging. Normal validation is appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "feat(python): add PMTiles archive helper" matches the main change. The PR adds Session.add_pmtiles and Map.add_pmtiles for PMTiles archives by URL or local path. It also includes a related …
Description check Passed The description follows the repository template. It has a Summary section that explains the new Session.add_pmtiles and Map.add_pmtiles helpers, the notebook project synchronization, the resolver chan…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(python): add PMTiles archive helper" matches the main change. The PR adds Session.add_pmtiles and Map.add_pmtiles for PMTiles archives by URL or local path. It also includes a related fix to the shared tile archive style resolver, which the title does not mention. The title is specific and concise, and it follows the conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary section that explains the new Session.add_pmtiles and Map.add_pmtiles helpers, the notebook project synchronization, the resolver change for explicit source layers, and the documented browser-accessible URL limitation. It has a Testing section that lists the Python test run, the offline regressions, the tiles library tests, cargo xtask ci, pre-commit, and the wasm build, along with the platforms not exercised. It has a Related issue section that references Part of #557 and states that only the Python item is covered.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit adds an atlas tile,
A map now reads the archive file.
Source layers bloom in lines and fill,
Styles take shape by caller’s will.
The notebook shows the path ahead,
And tests check what the layers said.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found nothing that needs fixing in this PR, and I posted no inline comments. It adds Session.add_pmtiles and Map.add_pmtiles to the Python package. It also changes archive_style in crates/tiles/src/source.rs so explicit source_layers are drawn for PMTiles archives. I read the diff and the surrounding Rust code. I did not run the tests.

Bugs

  • None found.
  • archive_style now checks spec.layers after own_style and before the metadata and basemap guess. A custom styleLayers still wins over source_layers, and source_layers wins over the default look. The docstring, docs/python.md and the Rust test all describe this order.
  • named_layers_style already limits itself to 64 names with .take(64), so passing the unbounded &spec.layers is safe. It also uses .get() and wrapping arithmetic, so there is no panic path.
  • The raster archive branch comes earlier in archive_style, so source_layers has no effect on raster archives. This is fine, but a short note in the docs would help (confidence: low).

Security

  • None found.
  • os.fspath(url) only turns the argument into a string. The URL and path handling stays in the engine.

Performance

  • None found.

Quality

  • Nit (confidence: low): add_pmtiles overwrites any kind, layers or styleLayers the caller passes through **params. That is probably intended. Rejecting kind explicitly would make the behaviour clearer, but it isn't needed.
  • The new Python tests use 127.0.0.1:9 URLs, so they don't touch the network. The local-path test builds the archive header in code, so no binary fixture is committed. The tests cover:
    • the project round trip;
    • JSON-text and array styles;
    • undo;
    • bad-style errors;
    • the notebook widget path.

AGENTS.md

  • No unwrap, expect or unsafe in non-test Rust code. The unwrap() calls are only inside #[cfg(test)].
  • No new interface strings, so the translation rules don't apply.
  • No new dependencies or assets.
  • Docs and README are updated alongside the change.

Change size

Compared: the whole PR against main (merge base 1890b5a to PR head 8526c27).

Metric Value
Files changed 6 (added 0, modified 6, removed 0, renamed 0)
Size before 77.9 KB
Size after 84.8 KB
Total size change +6.9 KB
File Before After Change
apps/rustgis-python/tests/test_session.py 8.5 KB 10.7 KB +2.1 KB
crates/tiles/src/source.rs 23.0 KB 24.7 KB +1.7 KB
apps/rustgis-python/python/rustgis/init.py 30.5 KB 31.9 KB +1.4 KB
docs/python.md 10.6 KB 11.8 KB +1.2 KB
apps/rustgis-python/tests/test_widget.py 3.0 KB 3.5 KB +468 B
apps/rustgis-python/README.md 2.2 KB 2.3 KB +65 B

@giswqs giswqs added the automerge Approve and squash-merge once the required checks pass label Oct 25, 2026
@giswqs
giswqs enabled auto-merge (squash) October 25, 2026 05:03
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-870/
Web app https://preview.rustgis.app/pr-870/app/
Commit 8526c27

GitHub Pages takes a minute or two to publish a new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Approve and squash-merge once the required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants