Skip to main content

The power of Rust for the Python STAC ecosystem

Project description

rustac

GitHub Workflow Status GitHub Workflow Status PyPI - Version PyPI - License Contributor Covenant

A Python package for STAC using Rust under the hood.

[!TIP] While you can pronounce "rustac" however you'd like, we like "ruh-stac".

Why?

Q: We already have PySTAC, so why rustac?

A: rustac can

If you don't need those things, rustac probably isn't for you — use pystac and its friend, pystac-client.

Installation

Install via pip:

# basic
python -m pip install rustac

# support arrow tables
python -m pip install 'rustac[arrow]'

Or via conda:

conda install conda-forge::rustac

From source

By default, rustac wants to find DuckDB on your system:

brew install duckdb  # if you're using Homebrew ... if not, get DuckDB another way
python -m pip install -U git+https://github.com/stac-utils/rustac-py

If you don't want to (or can't) install DuckDB, can build DuckDB as a "bundled" build (warning: it takes a while):

MATURIN_PEP517_ARGS="--features=duckdb-bundled" python -m pip install -U git+https://github.com/stac-utils/rustac-py

Usage

import asyncio
import rustac

async def main() -> None:
    # Search a STAC API
    items = await rustac.search(
        "https://landsatlook.usgs.gov/stac-server",
        collections="landsat-c2l2-sr",
        intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
        sortby="-properties.datetime",
        max_items=100,
    )

    # If you installed with `pystac[arrow]`:
    from geopandas import GeoDataFrame

    table = rustac.to_arrow(items)
    data_frame = GeoDataFrame.from_arrow(table)
    items = rustac.from_arrow(data_frame.to_arrow())

    # Write items to a stac-geoparquet file
    await rustac.write("/tmp/items.parquet", items)

    # Read items from a stac-geoparquet file as an item collection
    item_collection = await rustac.read("/tmp/items.parquet")

    # Use `search_to` for better performance if you know you'll be writing the items
    # to a file
    await rustac.search_to(
        "/tmp/items.parquet",
        "https://landsatlook.usgs.gov/stac-server",
        collections="landsat-c2l2-sr",
        intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
        sortby="-properties.datetime",
        max_items=100,
    )

asyncio.run(main())

See the documentation for details. In particular, our examples demonstrate some of the more interesting features.

Command line interface (CLI)

rustac comes with a CLI:

rustac -h

stac-geoparquet

rustac replicates much of the behavior in the stac-geoparquet library, and even uses some of the same Rust dependencies. We believe there are a couple of issues with stac-geoparquet that make rustac a worthy replacement:

  • The stac-geoparquet repo includes Python dependencies
  • It doesn't have a nice one-shot API for reading and writing
  • It includes some leftover code and logic from its genesis as a tool for the Microsoft Planetary Computer

We test to ensure compatibility between the two libraries, and we intend to consolidate to a single "stac-geoparquet" library at some point in the future.

Development

Get Rust, uv, and (optionally) libduckdb. Then:

git clone git@github.com:stac-utils/rustac-py.git
cd rustac-py
scripts/test

See CONTRIBUTING.md for more information about contributing to this project.

DuckDB

By default, this package expects libduckdb to be present on your system. If you get this sort of error when building:

  = note: ld: library 'duckdb' not found

Set your DUCKDB_LIB_DIR to point to your libduckdb. If you're using homebrew, that might look like this:

export DUCKDB_LIB_DIR=/opt/homebrew/lib

Alternatively, you can use the duckdb-bundled feature to build DuckDB bindings into the Rust library:

maturin dev --uv -F duckdb-bundled && pytest

[!WARNING] Building DuckDB bundled takes a long while.

Docs

If you want to run an off-cycle docs update (e.g. if you fixed something and want to post it without having to make a new release):

mike deploy [version] latest --push

License

rustac-py is dual-licensed under both the MIT license and the Apache license (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rustac-0.7.0b6.tar.gz (378.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rustac-0.7.0b6-cp311-abi3-manylinux_2_28_aarch64.whl (20.8 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

rustac-0.7.0b6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

rustac-0.7.0b6-cp311-abi3-macosx_11_0_arm64.whl (19.0 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

rustac-0.7.0b6-cp311-abi3-macosx_10_12_x86_64.whl (20.8 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file rustac-0.7.0b6.tar.gz.

File metadata

  • Download URL: rustac-0.7.0b6.tar.gz
  • Upload date:
  • Size: 378.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for rustac-0.7.0b6.tar.gz
Algorithm Hash digest
SHA256 36fbcaf58feaf460b5077d9647568134786835d07d613050c7b8322614718ed8
MD5 201a6563e164defdd67a349645f9d483
BLAKE2b-256 61976b0085e36899dc6646e0f2a7f84d5883143e60ae24162ea9fe9527fa17cd

See more details on using hashes here.

File details

Details for the file rustac-0.7.0b6-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rustac-0.7.0b6-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5567e159525cae1eeda1d0981c7fffc05926a08cfc3e253fcbfd91648613d0a8
MD5 85facf54e15781d424de6a5fa5244cc7
BLAKE2b-256 ccfd03a623d3890f37dbb75ffef5583b59b502f6f1c94018da1871ab4c8bd99e

See more details on using hashes here.

File details

Details for the file rustac-0.7.0b6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rustac-0.7.0b6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e23170c9025ab0bceb33dc3e9ca9b2ac93202c638914ddee64307c4e5e06b309
MD5 b4f3c55be88b86e2290ee69cec2379af
BLAKE2b-256 b61af534af88d812f7ca38eb91a0c7d9e8fb42687b1c4aa719afd0be8e063f81

See more details on using hashes here.

File details

Details for the file rustac-0.7.0b6-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustac-0.7.0b6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9677db4e82d847efb1d50617878ef45c18e8c8134d69dc537da8d0a90d64731f
MD5 d409ae8b9d804519bdfc623b04b0729f
BLAKE2b-256 70384bfc515f4283236b0378a76628f3454bf054665dfdc1412535d8b56566f1

See more details on using hashes here.

File details

Details for the file rustac-0.7.0b6-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rustac-0.7.0b6-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1bdef01fb91a6509320837b6ae79d3bb48cf1df42fab5b34425320410a5016f8
MD5 885e30ea8ccfc0f582923e3cd936b0a5
BLAKE2b-256 30aa225b30526e6bc62022f91c839628f3b6d5fc48928eb73a55aafce64692d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page