async-pmtiles
An asynchronous PMTiles reader for Python.
The PMTiles format is a cloud-native, compressed, single-file archive for storing tiled vector and raster map data.
Documentation: https://developmentseed.org/async-pmtiles/
Install
pip install async-pmtiles
Example
from async_pmtiles import PMTilesReader
from obstore.store import HTTPStore
store = HTTPStore("https://r2-public.protomaps.com/protomaps-sample-datasets")
src = await PMTilesReader.open("cb_2018_us_zcta510_500k.pmtiles", store=store)
# PMTiles Metadata
meta = await src.metadata()
# Spatial Metadata
bounds = src.bounds
minzoom, maxzoom = src.minzoom, src.maxzoom
# Is the data a Vector Tile Archive
assert src.is_vector
# PMTiles tiles type
src.tile_type
# Tile Compression
src.tile_compression
# Get Tile
data = await src.get_tile(x=0, y=0, z=0)
Custom Client
Here's an example with using a small wrapper around aiohttp to read from arbitrary URLs:
from dataclasses import dataclass
from aiohttp import ClientSession
from async_pmtiles import PMTilesReader, Store
@dataclass
class AiohttpAdapter(Store):
session: ClientSession
async def get_range_async(
self,
path: str,
*,
start: int,
length: int,
) -> bytes:
inclusive_end = start + length - 1
headers = {"Range": f"bytes={start}-{inclusive_end}"}
async with self.session.get(path, headers=headers) as response:
return await response.read()
async def main():
async with ClientSession() as session:
store = AiohttpAdapter(session)
url = "https://r2-public.protomaps.com/protomaps-sample-datasets/cb_2018_us_zcta510_500k.pmtiles"
src = await PMTilesReader.open(url, store=store)
assert src.header
assert src.bounds == (-176.684714, -14.37374, 145.830418, 71.341223)
assert src.minzoom == 0
assert src.maxzoom == 7
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async_pmtiles-0.1.0.tar.gz
(5.0 kB
view details)
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 async_pmtiles-0.1.0.tar.gz.
File metadata
- Download URL: async_pmtiles-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
995c45bd19e9859e9a1668463b02c1d7b702467120adf4edd0cdba1cfd0d6bf8
|
|
| MD5 |
5440793ae6d8c18ce8ba91d40b4ea7b2
|
|
| BLAKE2b-256 |
f9a8dda2094689ea38a5b2aa58b1ac7c9ee22bc2fad6f5a97c078030c541194d
|
File details
Details for the file async_pmtiles-0.1.0-py3-none-any.whl.
File metadata
- Download URL: async_pmtiles-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
219a787c7a2c37f93f8e311f257686dbdfaaa5d9bfbf51dd511c70b016836498
|
|
| MD5 |
61cad845ae709613745e9bae6bc672e4
|
|
| BLAKE2b-256 |
aa632fd3bc2a1e11d808cab5459f95b671ade84dd61e68f7bccd690da86032fb
|