Metadata-Version: 2.3
Name: async-pmtiles
Version: 0.1.0
Summary: Async version of protomaps/PMTiles.
Author: Vincent Sarago, Kyle Barron
Author-email: Vincent Sarago <vincent@developmentseed.com>, Kyle Barron <kyle@developmentseed.org>
License: MIT License
         
         Copyright (c) 2023 Development Seed
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Dist: pmtiles>=3.7.0
Requires-Python: >=3.11
Project-URL: Documentation, https://developmentseed.org/async-pmtiles/
Project-URL: Source, https://github.com/developmentseed/async-pmtiles
Description-Content-Type: text/markdown

# 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.

[PMTiles]: https://docs.protomaps.com/
[PMTiles format]: https://docs.protomaps.com/pmtiles/

**Documentation**: <https://developmentseed.org/async-pmtiles/>

## Install

```
pip install async-pmtiles
```

## Example

```python
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:

```py
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
```
