cog-tiles for Python
Web map tiles and stitched rasters from tile-aligned Cloud Optimized GeoTIFFs (COGs), local or in
S3, GCS, Azure or over HTTP, fetching only the bytes each tile needs.
Python bindings for the Rust cog-tiles crate used by
Martin.
import cog_tiles
cog = cog_tiles.open("s3://bucket/ortho.tif", options={"aws_region": "us-west-2"})
cog.min_zoom, cog.max_zoom, cog.tile_size, cog.format, cog.bounds
# One encoded tile, ready to serve or store (JPEG/WebP as stored, others as PNG).
png = cog.tile(18, 41936, 101296)
# Every tile in an area, fetched 64 at a time in the background, in arrival order.
for z, x, y, data in cog.tiles(bbox=(-122.42, 37.77, -122.41, 37.78), zoom=range(16, 19)):
...
# An area stitched into one (height, width, bands) uint8 array, decoded on all cores.
raster = cog.read((-122.42, 37.77, -122.41, 37.78), zoom=18)
raster.data.shape # (1311, 1166, 3)
raster.transform # GDAL geotransform in EPSG:3857
Many files, each covering one tile at a file zoom and named after it:
mosaic = cog_tiles.open_mosaic("s3://bucket/ortho/{quadkey}.tif", file_zoom=12)
raster = mosaic.read(bbox, zoom=18)
Templates use {quadkey}, or {x} and {y} with an optional {z} ({-y} counts rows from the
bottom, as in TMS). One file is found by listing the location when it is opened; the others are
opened on first use and cached.
With asyncio, e.g. in a tile server, every call that waits has an _async twin:
cog = await cog_tiles.open_async("s3://bucket/ortho.tif")
png = await cog.tile_async(18, 41936, 101296)
raster = await cog.read_async(bbox, zoom=18)
async for z, x, y, data in cog.tiles(bbox, zoom=18):
...
The fetches run on background threads, so awaited calls neither block the event loop nor hold a thread each.
What it reads
COGs on the WebMercatorQuad grid, as gdal_translate -of COG -co TILING_SCHEME=GoogleMapsCompatible
writes them: EPSG:3857, every image (and overview) at a zoom level's resolution and aligned to its
tiles, 8-bit samples. Each tile is one internal tile, so nothing is resampled. Other files raise
UnsupportedCogError saying why.
Uncompressed striped files are split into 256 px tiles.
Pages that are half the size of the previous page are used as overviews.
In a mosaic, square files without GeoTIFF tags are placed on the tile in their file name,
e.g. open_mosaic("s3://bucket/{quadkey}_rgb.tif", 16).
Performance
- All I/O and decoding runs in Rust with the GIL released;
readandtileskeepconcurrencyrequests in flight (64 by default) and decode on every core. - Wheels cover CPython 3.10 and later, including free-threaded CPython from 3.15t on.
- Headers are read once when opening: one request for a typical file, or one per IFD if IFDs come after the pixel data. Each tile is one range read. Tiles in the same row of a striped file share one read.
tile_pixelsandreadhand their buffer to NumPy without copying.- Ctrl-C interrupts any call. Cancelling an
_asynccall or dropping atiles()iterator stops its pending fetches.
Details
bboxis(west, south, east, north)in degrees, or(min_x, min_y, max_x, max_y)in meters withcrs="EPSG:3857". A raster covers the whole pixels the bbox touches;raster.boundsis the snapped extent. Pixels without data are 0, and a bbox without any data returnsNone.readrefuses rasters overmax_pixels(16384 x 16384 by default).CogandMosaicobjects pickle by reopening, so they work inmultiprocessingand PyTorchDataLoaderworkers. Forked processes get their own I/O threads.- Object store credentials come from the usual environment variables (
AWS_*,GOOGLE_*,AZURE_*);optionsoverrides them withobject_storekeys, e.g.{"aws_skip_signature": "true"}for public buckets. - Errors:
FileNotFoundError,ValueErrorfor invalid arguments,UnsupportedCogErrorfor files that cannot be read as tiles,CogTilesErrorfor everything else.
Development
cd cog-tiles-py
uv venv && uv pip install maturin pytest numpy
uv run maturin develop --release
uv run pytest
cog_tiles.pyi is generated from the bindings by just sync-cog-py-stubs; autofix.ci regenerates it on pull requests.
Metadata
Release files for cog-tiles 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cog_tiles-0.1.1.tar.gz | 172.2 kB | Without provenance | Details for cog_tiles-0.1.1.tar.gz |
Built distributions (wheels)
Total release size: 51.0 MB
Release files / cog_tiles-0.1.1.tar.gz
| Download URL | cog_tiles-0.1.1.tar.gz |
|---|---|
| Size | 172.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14b81ef904d9fbf36303122626a637227bba989bf710235b80c63029cc448718
|
|
BLAKE2b-256 checksum How to use checksums |
08e4304bb63032ca87a7c612efccd5bbf41c61ee1e6e07513fa3fb433e8b5f06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp315-abi3.abi3t-win_amd64.whl
| Download URL | cog_tiles-0.1.1-cp315-abi3.abi3t-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.15 Windows x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
fefa23eb699bc30e6ac6e32ad545bff0858a2038c7f25f09dba2dbcf465921a2
|
|
BLAKE2b-256 checksum How to use checksums |
462253bb3257467050cf0429aef2182c8a2280db37266761d01635f3ee749864
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
| Download URL | cog_tiles-0.1.1-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
c6f122c17211a8a9e0665be0ef90814da3a3155433b9afb01623d47c30be7b3f
|
|
BLAKE2b-256 checksum How to use checksums |
5a1a965e68054256a7d984d8e5f217fc0a6975c7bb0353039339805383d485e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
| Download URL | cog_tiles-0.1.1-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
75580fd0cd72e428ca4b149db7cbad85781d143b281074fd374038dd090b088c
|
|
BLAKE2b-256 checksum How to use checksums |
81170b6a495af818e67bc3644b641fdb642609b7419ad61a0271b5ae04b1a34d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp315-abi3.abi3t-macosx_11_0_arm64.whl
| Download URL | cog_tiles-0.1.1-cp315-abi3.abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.15 abi3 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9dfceb44a8ec9c0f0d65a6984b9ca1533eae290eb116527d8a3b54295e0eb83f
|
|
BLAKE2b-256 checksum How to use checksums |
03c5831a9e9ef8a423748cfa98c4ee0efccddf18178760b94313318ef049a0a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp315-abi3.abi3t-macosx_10_12_x86_64.whl
| Download URL | cog_tiles-0.1.1-cp315-abi3.abi3t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.15 abi3 abi3t macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
fdd3cf5a30895ca663da502c37fa9af77292e764cbc376937963ba7fce1cea23
|
|
BLAKE2b-256 checksum How to use checksums |
17a71539b6d5d72237f3e926e380d2cedd94391a98313fb823ce77397a627a69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp310-abi3-win_amd64.whl
| Download URL | cog_tiles-0.1.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c653470195c5eafec900742f50eac358d687971f432cd29f6a7878de910623bd
|
|
BLAKE2b-256 checksum How to use checksums |
122881efa2f5975c2b311b1db4e4c509b700ea9b3b7b537f2a567f700f2cd861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | cog_tiles-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0845852d08e850ca2a82eb5f8d1cb1f5a9f633f7850a041760ff767c8b297014
|
|
BLAKE2b-256 checksum How to use checksums |
bd529368c4291335c4447020faa16e323cf7095748e96e525b2cc83a1146dda1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | cog_tiles-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
468c025f49a479532361694004567a3bee6e1bbda5ba02be33a63fbdf1de3040
|
|
BLAKE2b-256 checksum How to use checksums |
22ec96ab446a40d526ba7bd9f66cc97abb1734e7ae2a0a75d5fa13dafd768579
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | cog_tiles-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ad46aae91bc0cfe266d13ffe735b0dca3852463649865ab78762984eddfa7be7
|
|
BLAKE2b-256 checksum How to use checksums |
d4d8eadb3327041b82c09e62fd2d1ba845b9a4901471f09fb17f58e9526007d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cog_tiles-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | cog_tiles-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8c42512628d77038be0d1832013604a48ce01eb89b62c4578d2c4c20d1431739
|
|
BLAKE2b-256 checksum How to use checksums |
2cbef97eb1c16d5fbfedc5eb2f77b793c018fbd5424424167ad72eb19e92b1e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cog-tiles 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.