Sling

1.5.15 · active · verified Thu Apr 16

Sling is a modern ELT (Extract, Load, Transform) data movement tool that allows users to rapidly move data between various databases, data warehouses, and cloud services using a simple Python API or CLI. It supports a wide range of connectors and focuses on ease of use and high performance. The current version is 1.5.15, with a rapid release cadence (multiple updates per month).

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a PostgreSQL source and a Snowflake target, then execute a data movement job. It uses environment variables for sensitive connection details, which is a recommended practice. Ensure you have the necessary `sling` extras installed (e.g., `sling[postgres,snowflake]`) and your environment variables configured for a successful run.

import os
from sling import Connection, Source, Target, run

# Configure connections using environment variables for sensitive data
# For a real run, ensure these environment variables are set:
# SLING_PG_HOST, SLING_PG_USER, SLING_PG_PASS, SLING_PG_DB
# SLING_SNF_ACCOUNT, SLING_SNF_USER, SLING_SNF_PASS, SLING_SNF_DB, SLING_SNF_WAREHOUSE

postgres_conn = Connection(
    name='my_postgres',
    type='postgres',
    host=os.environ.get('SLING_PG_HOST', 'localhost'),
    port=5432,
    user=os.environ.get('SLING_PG_USER', 'user'),
    password=os.environ.get('SLING_PG_PASS', 'password'),
    database=os.environ.get('SLING_PG_DB', 'source_db')
)

snowflake_conn = Connection(
    name='my_snowflake',
    type='snowflake',
    account=os.environ.get('SLING_SNF_ACCOUNT', 'your_account'),
    user=os.environ.get('SLING_SNF_USER', 'user'),
    password=os.environ.get('SLING_SNF_PASS', 'password'),
    database=os.environ.get('SLING_SNF_DB', 'target_db'),
    warehouse=os.environ.get('SLING_SNF_WAREHOUSE', 'COMPUTE_WH')
)

# Define source and target for a simple table copy
source_table = Source(
    connection=postgres_conn,
    object='public.my_source_table'
)

target_table = Target(
    connection=snowflake_conn,
    object='public.my_target_table',
    mode='full_refresh' # or 'append', 'incremental'
)

# Run the data sling job
try:
    result = run(source_table, target_table)
    print(f"Sling job completed. Rows replicated: {result.rows_replicated}")
except Exception as e:
    print(f"Sling job failed: {e}")

# Example of retrieving connection by name if already added to a global registry (e.g., via CLI or config file)
# connection = Connection.get_connection('my_postgres')

view raw JSON →