Sling + Python πŸš€

Examples of using Sling with Python

Installation

pip install sling or pip install sling[arrow] for streaming.

Then you should be able to run sling --help from command line or use it in your application as shown below.

See the wrapper source code at https://github.com/slingdata-io/sling-python.

Using the Replication class

Run a replication from file:

import yaml
from sling import Replication

# From a YAML file
replication = Replication(file_path="path/to/replication.yaml")
replication.run()

# Or load into object
with open('path/to/replication.yaml') as file:
  config = yaml.load(file, Loader=yaml.FullLoader)

replication = Replication(**config)

replication.run()

Build a replication dynamically

Using the Sling Class

For more direct control and streaming capabilities, you can use the Sling class, which mirrors the CLI interface. Available in latest version.

Basic Usage with run() method

Input Streaming - Python Data to Target

πŸ’‘ Tip: Install pip install sling[arrow] for better streaming performance and improved data type handling.

πŸ“Š DataFrame Support: The input parameter accepts lists of dictionaries, pandas DataFrames, or polars DataFrames. DataFrame support preserves data types when using Arrow format.

Output Streaming with stream()

High-Performance Streaming with stream_arrow()

πŸš€ Performance: The stream_arrow() method provides the highest performance streaming with full data type preservation by using Apache Arrow's columnar format. Requires pip install sling[arrow].

πŸ“Š Type Safety: Unlike stream() which may convert data types during CSV serialization, stream_arrow() preserves exact data types including integers, floats, timestamps, and more.

Round-trip Examples

Using the Pipeline class

Run a Pipeline:

Last updated

Was this helpful?