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
Replication classRun 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
Sling ClassFor 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
run() methodInput Streaming - Python Data to Target
π‘ Tip: Install
pip install sling[arrow]for better streaming performance and improved data type handling.
Be careful with large numbers of Sling invocations using input or stream() methods when working with external systems (databases, file systems). Each call re-opens the connection since it invokes the underlying sling binary. For better performance and connection reuse, consider using the Replication class instead, which maintains open connections across multiple operations.
π DataFrame Support: The
inputparameter accepts lists of dictionaries, pandas DataFrames, or polars DataFrames. DataFrame support preserves data types when using Arrow format.
Output Streaming with stream()
stream()High-Performance Streaming with stream_arrow()
stream_arrow()π Performance: The
stream_arrow()method provides the highest performance streaming with full data type preservation by using Apache Arrow's columnar format. Requirespip 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
Pipeline classRun a Pipeline:
Last updated
Was this helpful?