API-compatible replacement for the Mercantile library with full type safety.
Project description
tilemath
A modern, type-safe Python library for spherical mercator coordinate and tile utilities. Designed as an API-compatible replacement for mercantile with full type safety and minimal dependencies.
Features
- Full Type Safety: Complete type annotations for all functions and classes
- API Compatible: Drop-in replacement for mercantile with the same interface
- Minimal Dependencies: Zero runtime dependencies for core functionality
- Modern Python: Built for Python 3.10+ with modern language features
- Fast: Optimized implementations of coordinate transformations and tile operations
Installation
pip install tilemath
Or with uv:
uv add tilemath
Quick Start
import tilemath.mercantile as mercantile
# Convert longitude/latitude to tile coordinates
tile = mercantile.tile(-122.4194, 37.7749, 12) # San Francisco
print(f"Tile: {tile.x}, {tile.y}, {tile.z}")
# Get bounding box for a tile
bbox = mercantile.bounds(tile)
print(f"Bounds: {bbox}")
# Convert tile to quadkey
quadkey = mercantile.quadkey(tile)
print(f"Quadkey: {quadkey}")
API Reference
The library provides the same API as mercantile, including:
tile(lng, lat, zoom)- Get tile containing a longitude/latitudebounds(tile)- Get bounding box of a tilexy(lng, lat)- Convert longitude/latitude to web mercator coordinateslnglat(x, y)- Convert web mercator coordinates to longitude/latitudequadkey(tile)- Convert tile to Microsoft quadkeyquadkey_to_tile(quadkey)- Convert quadkey to tiletiles(west, south, east, north, zooms)- Generate tiles for a bounding boxchildren(tile)- Get child tilesparent(tile)- Get parent tileneighbors(tile)- Get neighboring tiles
Type Safety
tilemath adds complete type annotations:
from tilemath.mercantile import Tile, Bbox
# All functions have proper type hints
def process_tile(tile: Tile) -> Bbox:
return bounds(tile)
# Type checkers will catch errors
tile = Tile(x=1, y=2, z=3)
bbox: Bbox = process_tile(tile)
Requirements
- Python 3.10 or higher
- No runtime dependencies
Development
This project uses uv for dependency management and development workflows.
Setup
# Clone the repository
git clone https://github.com/eddieland/tilemath.git
cd tilemath
# Install dependencies
make install
Running Tests
# Run all tests
make test
# Run specific test file
uv run pytest tests/test_mercantile_upstream.py -v
Code Quality
# Run linting and type checking
make lint
# Run everything (install, lint, test)
make
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Acknowledgments
This project is inspired by and aims to be compatible with mercantile by Sean Gillies and contributors.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tilemath-0.1.1.tar.gz.
File metadata
- Download URL: tilemath-0.1.1.tar.gz
- Upload date:
- Size: 50.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c698197867754ef6e395be1f140af2b3921a3933c10211074741987f6056ec66
|
|
| MD5 |
b3e981390f7022027525dead5edc2412
|
|
| BLAKE2b-256 |
c1a3bfd643ef929d019eff93aad88ddbf45029ff8d8218d105b8fc656b7238f1
|
Provenance
The following attestation bundles were made for tilemath-0.1.1.tar.gz:
Publisher:
publish.yml on eddieland/tilemath
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tilemath-0.1.1.tar.gz -
Subject digest:
c698197867754ef6e395be1f140af2b3921a3933c10211074741987f6056ec66 - Sigstore transparency entry: 243605746
- Sigstore integration time:
-
Permalink:
eddieland/tilemath@4963247114472856d4933de4aeb535d84b4e8d40 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eddieland
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4963247114472856d4933de4aeb535d84b4e8d40 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tilemath-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tilemath-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bf3864fa3fc1143290e45ee5aff6204876a5a3e750a235496e42b73ba8b0d75
|
|
| MD5 |
2d30adc1004b6d159639a884ffbd2ef3
|
|
| BLAKE2b-256 |
90ea3ae13814093175e7e3b6e6ed914b10a9683599a7b3234692feb775b16d93
|
Provenance
The following attestation bundles were made for tilemath-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on eddieland/tilemath
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tilemath-0.1.1-py3-none-any.whl -
Subject digest:
1bf3864fa3fc1143290e45ee5aff6204876a5a3e750a235496e42b73ba8b0d75 - Sigstore transparency entry: 243605747
- Sigstore integration time:
-
Permalink:
eddieland/tilemath@4963247114472856d4933de4aeb535d84b4e8d40 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eddieland
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4963247114472856d4933de4aeb535d84b4e8d40 -
Trigger Event:
release
-
Statement type: