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.
Files in Web Mercator or a UTM zone, listed by a gdaltindex tile index and reprojected onto
Web Mercator tiles:
# gdaltindex -f GPKG -t_srs EPSG:4326 naip.gpkg *.tif
naip = cog_tiles.open_tile_index("naip.gpkg", min_zoom=12, nodata=0)
naip.bounds # the union of the files' footprints
png = naip.tile(14, 2619, 6334)
The whole index is read when it is opened. Each tile is painted from the files that touch it, in the
index's row order, so a pixel takes the first file's data; it is a PNG with an alpha band that is
transparent where no file has data. bands picks the bands served, counted from 1 ([1, 2, 3] by
default, or one band for gray). Locations may be paths relative to the index, URLs, or GDAL
/vsis3/, /vsigs/, /vsiaz/ and /vsicurl/ paths, read with options as in open.
Or the items a STAC API finds for each tile:
naip = cog_tiles.open_stac(
"https://earth-search.aws.element84.com/v1", "naip", "image", min_zoom=13,
datetime="2020-01-01T00:00:00Z/..", query={"naip:state": {"eq": "ca"}}, nodata=0,
options={"aws_request_payer": "true"},
)
One search covers a tile at search_zoom (min_zoom by default) and serves every tile below it;
results are cached for search_expiry seconds. Items are painted newest first (order="oldest"
for the other way), each pixel from the first item with data for it. bands selects bands by
number or eo:bands name, ["red", "green", "blue"] by default.
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.
Tile format
format, quality and background re-encode every tile, on open and open_mosaic alike:
cog = cog_tiles.open("s3://bucket/ortho.tif", format="webp", quality=80)
cog = cog_tiles.open("s3://bucket/ortho.tif", format="webp", quality="lossless")
cog = cog_tiles.open("s3://bucket/ortho.tif", format="jpeg", quality=90, background="black")
format |
quality |
transparency |
|---|---|---|
png |
- | kept |
webp |
1 to 100 or "lossless", 80 when unset |
kept exactly, even lossy |
jpeg |
1 to 100, 80 when unset | painted over background: a CSS color or (r, g, b), white when unset |
Without format, JPEG and WebP tiles are returned as stored and others as PNG. With it, every tile
is decoded and encoded again, also JPEG and WebP tiles, so lossy tiles lose detail again.
tile_pixels and read return the decoded pixels either way.
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.11 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).Cog,Mosaic,TileIndexandStacobjects 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.3
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.3.tar.gz | 214.7 kB | With provenance | Details for cog_tiles-0.1.3.tar.gz |
Built distributions (wheels)
Total release size: 69.9 MB
Release files / cog_tiles-0.1.3.tar.gz
| Download URL | cog_tiles-0.1.3.tar.gz |
|---|---|
| Size | 214.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90baf14f3fc87d7c79c0d48109269c2dbc73aeb8f85eb446c308ecd1b0dad32b
|
|
BLAKE2b-256 checksum How to use checksums |
2d192389f3a963a085f2ad0dca8a13887cc7dc6ac3187d94a603e9033224abb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp315-abi3.abi3t-win_amd64.whl
| Download URL | cog_tiles-0.1.3-cp315-abi3.abi3t-win_amd64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.15 Windows x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
50b6b9634df07035e5cb2b63845ff739e91178fc31b7f0a2d876ba9b7359021a
|
|
BLAKE2b-256 checksum How to use checksums |
eed9acab79db4dcc78ddc8fb6e17f974a4b6f393d2fa74955b266213470aa5b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
| Download URL | cog_tiles-0.1.3-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 7.5 MB |
| Tags | CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
f7ad2ffa041dad1779aee0b59fc85f9b27651d7a23ea394e90419678e7fb7683
|
|
BLAKE2b-256 checksum How to use checksums |
3161a5e9389bca3c8260ca80521a022fd298389c5c0fad1c9c6b5b0beabff9db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
| Download URL | cog_tiles-0.1.3-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
65450ff3a2d6aca4a17526e228d8a50536777e20196b9c5915859fa1eec89d24
|
|
BLAKE2b-256 checksum How to use checksums |
2b366cf5c7a5f9540d57ff01b375e5aa881f48ada57725058aa0f7cf4f7b7c42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl
| Download URL | cog_tiles-0.1.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.15 abi3 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
83a5eb58c68b6ede27eb1a2b41f8570ee8c7704b24fee8f7ab04f2a91309f5b0
|
|
BLAKE2b-256 checksum How to use checksums |
bd4d409bb1c620fb6712c76d662c6caefeb4f869c0566ddcba227d0d8361bed8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp315-abi3.abi3t-macosx_10_12_x86_64.whl
| Download URL | cog_tiles-0.1.3-cp315-abi3.abi3t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.15 abi3 abi3t macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
761975c91821ee155e1232b817afd54a2462510b9ba429862b81ebb4a3581653
|
|
BLAKE2b-256 checksum How to use checksums |
003c84227d78e9a4957eb00d60ae66f98b176c55de4834d7316dbcc2bdc58152
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp311-abi3-win_amd64.whl
| Download URL | cog_tiles-0.1.3-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
55a2c39d1c019e98f629c2ffc20d362755411516add20932ce4f7cf9e5c78beb
|
|
BLAKE2b-256 checksum How to use checksums |
04a6b31086c922df7edb2e519973e258ab51b77ce8045d1f75883c08758b932d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | cog_tiles-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 7.5 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2945f7584dbe3e6f4510c5e166c52c982125e31f49f7596549a23054e05d513a
|
|
BLAKE2b-256 checksum How to use checksums |
5bb537a8fb3586291a14f4932fbc28e729f2ca65ff573684958cb11c68509094
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | cog_tiles-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
736189101b4892979c575109bf48222ffc75cf14b120410cd33b099f897a1b59
|
|
BLAKE2b-256 checksum How to use checksums |
be59b629c77024e0ca365943917e93ffc284ea0c4a3317da73795e9da54217f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | cog_tiles-0.1.3-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5256e5872ffe431f6c8e79356ff4421ab0efd822cb04bbe4601eeafab14455c6
|
|
BLAKE2b-256 checksum How to use checksums |
dd5796aec0265ef93a33ed92600d029f5b1ddb7e13077c3e62fe1fe6e2028577
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / cog_tiles-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | cog_tiles-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 7.1 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
29feb1f288a2ab69a9f7d27b8375fcd1974763dc87277e57e6171b912ea93577
|
|
BLAKE2b-256 checksum How to use checksums |
351dc176ea622ada282b95985396af92e431ff12d03f7e4cdb3169b4dd5fd028
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for cog-tiles 0.1.3
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.
Full provenance
All 11 files in this release have been uploaded with provenance metadata.
Attestation for cog_tiles-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA 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.