Skip to content

Commit 9a311f9

Browse files
authored
feat: Simplify Store protocol to only define length (#12)
* feat: Simplify GetRangeAsync to only define `length` * Rename to Store and update readme and tests
1 parent 7d3b5bb commit 9a311f9

File tree

8 files changed

+710
-286
lines changed

8 files changed

+710
-286
lines changed

README.md

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
1-
# aiopmtiles
1+
# async-pmtiles
22

3-
<p align="center">
4-
<em>Async Version of Python PMTiles Reader.</em>
5-
</p>
6-
<p align="center">
7-
<a href="https://github.com/developmentseed/aiopmtiles/actions?query=workflow%3ACI" target="_blank">
8-
<img src="https://github.com/developmentseed/aiopmtiles/workflows/CI/badge.svg" alt="Test">
9-
</a>
10-
<a href="https://codecov.io/gh/developmentseed/aiopmtiles" target="_blank">
11-
<img src="https://codecov.io/gh/developmentseed/aiopmtiles/branch/main/graph/badge.svg" alt="Coverage">
12-
</a>
13-
<a href="https://pypi.org/project/aiopmtiles" target="_blank">
14-
<img src="https://img.shields.io/pypi/v/aiopmtiles?color=%2334D058&label=pypi%20package" alt="Package version">
15-
</a>
16-
<a href="https://pypistats.org/packages/aiopmtiles" target="_blank">
17-
<img src="https://img.shields.io/pypi/dm/aiopmtiles.svg" alt="Downloads">
18-
</a>
19-
<a href="https://github.com/developmentseed/aiopmtiles/blob/main/LICENSE" target="_blank">
20-
<img src="https://img.shields.io/github/license/developmentseed/aiopmtiles.svg" alt="Downloads">
21-
</a>
22-
</p>
3+
An asynchronous [PMTiles] reader for Python.
234

24-
---
5+
The [PMTiles format] is a cloud-native, compressed, single-file archive for storing tiled vector and raster map data.
256

26-
**Documentation**: <a href="https://developmentseed.org/aiopmtiles/" target="_blank">https://developmentseed.org/aiopmtiles/</a>
7+
[PMTiles]: https://docs.protomaps.com/
8+
[PMTiles format]: https://docs.protomaps.com/pmtiles/
279

28-
**Source Code**: <a href="https://github.com/developmentseed/aiopmtiles" target="_blank">https://github.com/developmentseed/aiopmtiles</a>
10+
**Documentation**: <https://developmentseed.org/async-pmtiles/>
2911

30-
---
12+
## Install
3113

32-
`aiopmtiles` is a python `Async I/O` version of the great [PMTiles](https://github.com/protomaps/PMTiles) python reader.
33-
34-
The [**PMTiles**](https://github.com/protomaps/PMTiles) format is a *Cloud-optimized + compressed single-file tile archives for vector and raster maps*.
35-
36-
## Installation
37-
38-
```bash
39-
$ python -m pip install pip -U
40-
41-
# From Pypi
42-
$ python -m pip install aiopmtiles
43-
44-
# Or from source
45-
$ python -m pip install git+http://github.com/developmentseed/aiopmtiles
14+
```
15+
pip install async-pmtiles
4616
```
4717

4818
## Example
@@ -74,18 +44,40 @@ src.tile_compression
7444
data = await src.get_tile(x=0, y=0, z=0)
7545
```
7646

77-
## Contribution & Development
78-
79-
See [CONTRIBUTING.md](https://github.com/developmentseed/aiopmtiles/blob/main/CONTRIBUTING.md)
80-
81-
## Authors
82-
83-
See [contributors](https://github.com/developmentseed/aiopmtiles/graphs/contributors)
84-
85-
## Changes
86-
87-
See [CHANGES.md](https://github.com/developmentseed/aiopmtiles/blob/main/CHANGES.md).
88-
89-
## License
90-
91-
See [LICENSE](https://github.com/developmentseed/aiopmtiles/blob/main/LICENSE)
47+
### Custom Client
48+
49+
Here's an example with using a small wrapper around `aiohttp` to read from arbitrary URLs:
50+
51+
```py
52+
from dataclasses import dataclass
53+
from aiohttp import ClientSession
54+
from async_pmtiles import PMTilesReader, Store
55+
56+
@dataclass
57+
class AiohttpAdapter(Store):
58+
session: ClientSession
59+
60+
async def get_range_async(
61+
self,
62+
path: str,
63+
*,
64+
start: int,
65+
length: int,
66+
) -> bytes:
67+
inclusive_end = start + length - 1
68+
headers = {"Range": f"bytes={start}-{inclusive_end}"}
69+
async with self.session.get(path, headers=headers) as response:
70+
return await response.read()
71+
72+
73+
async def main():
74+
async with ClientSession() as session:
75+
store = AiohttpAdapter(session)
76+
url = "https://r2-public.protomaps.com/protomaps-sample-datasets/cb_2018_us_zcta510_500k.pmtiles"
77+
src = await PMTilesReader.open(url, store=store)
78+
79+
assert src.header
80+
assert src.bounds == (-176.684714, -14.37374, 145.830418, 71.341223)
81+
assert src.minzoom == 0
82+
assert src.maxzoom == 7
83+
```

docs/usage.md

Lines changed: 0 additions & 192 deletions
This file was deleted.

mkdocs.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ extra:
2626
# Layout
2727
nav:
2828
- Home: "index.md"
29-
- Usage: "usage.md"
3029
- API Reference: "api.md"
3130
- Changelog: "CHANGELOG.md"
3231
- Contributing: "DEVELOP.md"
@@ -108,14 +107,9 @@ plugins:
108107
- griffe_inherited_docstrings
109108

110109
inventories:
111-
- https://affine.readthedocs.io/en/latest/objects.inv
112-
- https://developmentseed.org/async-tiff/latest/objects.inv
113-
- https://developmentseed.org/morecantile/objects.inv
110+
- https://developmentseed.org/obspec/latest/objects.inv
114111
- https://developmentseed.org/obstore/latest/objects.inv
115112
- https://docs.python.org/3/objects.inv
116-
- https://numpy.org/doc/stable/objects.inv
117-
- https://pyproj4.github.io/pyproj/stable/objects.inv
118-
- https://rasterio.readthedocs.io/en/stable/objects.inv
119113

120114
# https://github.com/developmentseed/titiler/blob/50934c929cca2fa8d3c408d239015f8da429c6a8/docs/mkdocs.yml#L115-L140
121115
markdown_extensions:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ build-backend = "uv_build"
3232

3333
[dependency-groups]
3434
dev = [
35+
"aiohttp>=3.13.3",
3536
"build>=1.4.0",
3637
"ipykernel>=7.2.0",
3738
"obstore>=0.8.2",

src/async_pmtiles/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""async-pmtiles: asynchronous interface for reading PMTiles files."""
22

3-
from ._reader import PMTilesReader
3+
from ._reader import PMTilesReader, Store
44
from ._version import __version__
55

6-
__all__ = ["PMTilesReader", "__version__"]
6+
__all__ = ["PMTilesReader", "Store", "__version__"]

0 commit comments

Comments
 (0)