|
1 | | -# aiopmtiles |
| 1 | +# async-pmtiles |
2 | 2 |
|
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. |
23 | 4 |
|
24 | | ---- |
| 5 | +The [PMTiles format] is a cloud-native, compressed, single-file archive for storing tiled vector and raster map data. |
25 | 6 |
|
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/ |
27 | 9 |
|
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/> |
29 | 11 |
|
30 | | ---- |
| 12 | +## Install |
31 | 13 |
|
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 |
46 | 16 | ``` |
47 | 17 |
|
48 | 18 | ## Example |
@@ -74,18 +44,40 @@ src.tile_compression |
74 | 44 | data = await src.get_tile(x=0, y=0, z=0) |
75 | 45 | ``` |
76 | 46 |
|
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 | +``` |
0 commit comments