Links

Getting Started with Sling CLI

An introduction to using the Sling CLI tool.

Getting Started

sling CLI is a free tool that allows data extraction and loading from / into many popular databases / storage platforms. Follow the instructions below to install it on your respective operating system.

Installation

Brew on Mac

brew install slingdata-io/sling/sling
# You're good to go!
sling -h

Scoop on Windows

scoop bucket add sling https://github.com/slingdata-io/scoop-sling.git
scoop install sling
# You're good to go!
sling -h

Binary Download

Linux
Mac
Windows
Docker
# Download sling binary (amd64)
curl -LO 'https://f.slingdata.io/linux/sling' && chmod +x sling
# You're good to go
./sling --help
# run portion below to have `sling` command available
# in $PATH for current user permanently
BIN_FOLDER="$HOME/bin" && \
mkdir -p $BIN_FOLDER && \
mv sling $BIN_FOLDER
echo "
export PATH=$BIN_FOLDER:\$PATH
" >> ~/.bashrc # or ~/.zshrc
# now need to restart shell session to pick up sling command
# Download sling binary
curl -LO 'https://f.slingdata.io/mac/sling' && chmod +x sling
# You're good to go
./sling --help
# run portion below to have `sling` command available
# in $PATH for current user permanently
BIN_FOLDER="$HOME/bin" && \
mkdir -p $BIN_FOLDER && \
mv sling $BIN_FOLDER
echo "
export PATH=$BIN_FOLDER:\$PATH
" >> ~/.bashrc # or ~/.zshrc
# now need to restart shell session to pick up sling command
# Start a PowerShell session
# create sling folder
$slingFolder = "$env:userprofile\AppData\Local\Programs\Sling"
mkdir -Force -p $slingFolder
$ProgressPreference = 'SilentlyContinue' # this will speed up download
Invoke-WebRequest "https://f.slingdata.io/windows/sling.exe" -OutFile $slingFolder\sling.exe
# run this to have `sling` command available in $PATH for current user
[Environment]::SetEnvironmentVariable("PATH", $env:Path + ";$slingFolder", [System.EnvironmentVariableTarget]::User)
# need to restart powershell session to pick up sling command
sling --help
docker pull slingdata/sling
docker run --rm -i slingdata/sling --help

Setting up your Connections

Sling looks for credentials in several places:
  • Environment Variables
  • Sling Env File (located at ~/.sling/env.yaml)
  • DBT Profiles Files (located at ~/.dbt/profiles.yml)
Please see environment for more details.

Using Sling

sling CLI is designed to be easy to use. Say we want to load a CSV file into a PostgreSQL database. We could run the following command:
Linux
Mac
Windows
Docker
export MY_PG='postgresql://user:[email protected]:5432/db1'
sling run --src-stream file:///path/to/myfile.csv --tgt-conn MY_PG --tgt-object public.my_new_data
# OR pipe it in
cat /path/to/myfile.csv | sling run --tgt-conn MY_PG --tgt-object public.my_new_data
export MY_PG='postgresql://user:[email protected]:5432/db1'
sling run --src-stream file:///path/to/myfile.csv --tgt-conn MY_PG --tgt-object public.my_new_data
# OR pipe it in
cat /path/to/myfile.csv | sling run --tgt-conn MY_PG --tgt-object public.my_new_data
# using windows Powershell
$env:MY_PG = 'postgresql://user:[email protected]:5432/db1'
sling run --src-stream file://C:/path/to/myfile.csv --tgt-conn MY_PG --tgt-object public.my_new_data
# OR pipe it in
cat C:\path\to\myfile.csv | sling run --tgt-conn MY_PG --tgt-object public.my_new_data
export MY_PG='postgresql://user:[email protected]:5432/db1'
docker run --rm -i -e MY_PG -v /path/to/myfile.csv slingdata/sling run --src-stream file:///path/to/myfile.csv --tgt-conn MY_PG --tgt-object public.my_new_data
Demo of some sling action
Notice how we didn't need to specify table columns / data types. sling automatically detects those and creates the appropriate columns. We can also notice that we are using an environment variable MY_PG for connecting to our PostgreSQL server.
See here for configuration details and lots of examples!

With Python

If you have Python pip installed, you can simply run:
pip install sling
You call also check out the Python wrapper library on github.
from sling import Sling
config = {
'source': {
'conn': 'MY_PG',
'stream': "select * from my_table",
},
'target': {
'conn': "MY_AWS_S3",
'object': "s3://my_bucket/my_folder/new_file.csv",
},
}
Sling(**config).run()