Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

astro

workflows made easy

Python versions License Development Status PyPI downloads Contributors Commit activity CI codecov

astro allows rapid and clean development of {Extract, Load, Transform} workflows using Python. It helps DAG authors to achieve more with less code. It is powered by Apache Airflow and maintained by Astronomer.

:warning: Disclaimer This project is in a preview release state. In other words, it is not production-ready yet. The interfaces may change. We welcome users to try out the interfaces and provide us with feedback.

Install

Astro is available at PyPI. Use the standard Python installation tools.

To install a cloud-agnostic version of Astro, run:

pip install astro-sdk-python

If using cloud providers, install using the optional dependencies of interest:

pip install astro-sdk-python[amazon,google,snowflake,postgres]

Quick-start

After installing Astro, copy the following example dag calculate_popular_movies.py to a local directory named dags:

from datetime import datetime
from airflow import DAG
from astro import sql as aql
from astro.sql.table import Table


@aql.transform()
def top_five_animations(input_table: Table):
    return """
        SELECT Title, Rating
        FROM {{input_table}}
        WHERE Genre1=='Animation'
        ORDER BY Rating desc
        LIMIT 5;
    """


with DAG(
    "calculate_popular_movies",
    schedule_interval=None,
    start_date=datetime(2000, 1, 1),
    catchup=False,
) as dag:
    imdb_movies = aql.load_file(
        path="https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb.csv",
        task_id="load_csv",
        output_table=Table(
            table_name="imdb_movies", database="sqlite", conn_id="sqlite_default"
        ),
    )

    top_five_animations(
        input_table=imdb_movies,
        output_table=Table(
            table_name="top_animation", database="sqlite", conn_id="sqlite_default"
        ),
    )

Set up a local instance of Airflow by running:

export AIRFLOW_HOME=`pwd`
export AIRFLOW__CORE__ENABLE_XCOM_PICKLING=True

airflow db init

Create an SQLite database for the example to run with and run the DAG:

# The sqlite_default connection has different host for MAC vs. Linux
export SQL_TABLE_NAME=`airflow connections get sqlite_default -o yaml | grep host | awk '{print $2}'`

sqlite3 "$SQL_TABLE_NAME" "VACUUM;"
airflow dags test calculate_popular_movies `date -Iseconds`

Check the top five animations calculated by your first Astro DAG by running:

sqlite3 "$SQL_TABLE_NAME" "select * from top_animation;" ".exit"

You should see the following output:

$ sqlite3 "$SQL_TABLE_NAME" "select * from top_animation;" ".exit"
Toy Story 3 (2010)|8.3
Inside Out (2015)|8.2
How to Train Your Dragon (2010)|8.1
Zootopia (2016)|8.1
How to Train Your Dragon 2 (2014)|7.9

Requirements

Because astro relies on the Task Flow API and it depends on Apache Airflow >= 2.1.0.

Supported technologies

Databases File types File locations
Google BigQuery CSV Amazon S3
Postgres JSON Filesystem
Snowflake NDJSON Google GCS
SQLite Parquet

Available operations

A summary of the currently available operations in astro. More details are available in the reference guide.

  • load_file: load a given file into a SQL table
  • transform: applies a SQL select statement to a source table and saves the result to a destination table
  • truncate: remove all records from a SQL table
  • run_raw_sql: run any SQL statement without handling its output
  • append: insert rows from the source SQL table into the destination SQL table, if there are no conflicts
  • merge: insert rows from the source SQL table into the destination SQL table, depending on conflicts:
    • ignore: do not add rows that already exist
    • update: replace existing rows with new ones
  • export_file: export SQL table rows into a destination file
  • dataframe: export given SQL table into in-memory Pandas data-frame

Documentation

The documentation is a work in progress, and we aim to follow the Diátaxis system:

  • Tutorial: a hands-on introduction to astro
  • How-to guides: simple step-by-step user guides to accomplish specific tasks
  • Reference guide: commands, modules, classes and methods
  • Explanation: Clarification and discussion of key decisions when designing the project.

Changelog

We follow Semantic Versioning for releases. Check the changelog for the latest changes.

Release Managements

To learn more about our release philosophy and steps, check here

Contribution Guidelines

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

Read the Contribution Guideline for a detailed overview on how to contribute.

As contributors and maintainers to this project, you should abide by the Contributor Code of Conduct.

License

Apache Licence 2.0

Download files

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

Source Distribution

astro-sdk-python-0.9.0b1.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

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

astro_sdk_python-0.9.0b1-py3-none-any.whl (70.4 kB view details)

Uploaded Python 3

File details

Details for the file astro-sdk-python-0.9.0b1.tar.gz.

File metadata

  • Download URL: astro-sdk-python-0.9.0b1.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.12

File hashes

Hashes for astro-sdk-python-0.9.0b1.tar.gz
Algorithm Hash digest
SHA256 1343a2cd986868e2da5929bbea5cf7c2a01388d2ad1c39b385149deae0bc0918
MD5 ee62bc6b4cc15b6a9836227dc35a6b7e
BLAKE2b-256 e4d7aee7320e31f52d3c5e9679036e286d436dc9e90e198aa2bc136a62af467a

See more details on using hashes here.

File details

Details for the file astro_sdk_python-0.9.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for astro_sdk_python-0.9.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 c478b38504a462706f7537423d48e9e9676d495f8d2edcf6d330926adbf99d33
MD5 13c2914a1a65f3577f8a8720674e85d7
BLAKE2b-256 71146f5b56e9e86383357cf0b5e86bfcf711aad924f48553e9945198fc323b25

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 Sentry Error logging StatusPage Status page