The goal of this tool is to provide CLI access to the Lytics API. It also functions as a developers aid to enable writing and testing LQL (Lytics Query Language) as easily as possible.
We would love any feature requests or ideas that would make this useful to you.
Download a binary from the releases page and rename to lytics
:
# linux/amd64
curl -Lo lytics https://github.com/lytics/lytics/releases/download/latest/lytics_linux \
&& chmod +x lytics \
&& sudo mv lytics /usr/local/bin/
# darwin/amd64
curl -Lo lytics https://github.com/lytics/lytics/releases/download/latest/lytics_mac \
&& chmod +x lytics \
&& sudo mv lytics /usr/local/bin/
Or install from source:
git clone https://github.com/lytics/lytics.git
go build
go install
Or install from the repository via go
:
go get -u github.com/lytics/lytics
All examples use JQ to prettify the JSON output.
export LIOKEY="your_api_key"
lytics --help
Exporting CSV files, with usage.
Example
# Scan a segment by id
lytics segment scan ab93a9801a72871d689342556b0de2e9 | jq '.'
# Scan a segment by slug
lytics segment scan last_2_hours | jq '.'
# write out this segment to a temp file so we can play with JQ
lytics segment scan last_2_hours > /tmp/users.json
# same thing but with an "ad hoc query"
lytics segment scan '
FILTER AND (
lastvisit_ts > "now-2d"
EXISTS email
)
FROM user
' > /tmp/users.json
# use JQ to output a few fields
cat /tmp/users.json | \
jq -c ' {country: .country, city: .city, org: .org, uid: ._uid, visitct: .visitct} '
# create a CSV file from these users
echo "country,city,org,uid,visitct\n" > /tmp/users.csv
cat /tmp/users.json | \
jq -r ' [ .country, .city, .org, ._uid, .visitct ] | @csv ' >> /tmp/users.csv
- Create NAME.lql (any name) file in a folder.
- Assuming you already have data collected, it will use our API to show recent examples against that LQL.
You can open and edit in an editor. Every time you edit it will print resulting users it interpreted from recent data to our API.
Example
# get your API key from the web app account settings screen
export LIOKEY="your_api_key"
cd /path/to/your/project
# create an LQL file
# - utilize the Lytics app "Data -> Data Streams" section to see
# data fields you are sending to Lytics.
# you can create this in an editor as well
echo '
SELECT
user_id,
name,
todate(ts),
match("user.") AS user_attributes,
map(event, todate(ts)) as event_times KIND map[string]time MERGEOP LATEST
FROM default
INTO USER
BY user_id
ALIAS my_query
' > default.lql
# start watching
lytics schema queries watch .
# now edit JSON results of how data is interpreted is output
- Create NAME.lql (any name) file in a folder.
- Create NAME.json (any name, must match LQL file name) in folder.
- Run the
lytics watch
command from the folder with files. - Edit .lql, or .json files, upon change the evaluated result of the .lql, JSON will be output.
Example
# get your API key from web app account settings
export LIOKEY="your_api_key"
cd /tmp
# start watching in background
lytics schema queries watch &
# create an LQL file
echo '
SELECT
user_id,
name,
todate(ts),
match("user.") AS user_attributes,
map(event, todate(ts)) as event_times KIND map[string]time MERGEOP LATEST
FROM data
INTO USER
BY user_id
ALIAS hello
' > hello.lql
# Create an array of JSON events to feed into LQL query
echo '[
{"user_id":"dump123","name":"Down With","company":"Trump", "event":"project.create", "ts":"2016-11-09"},
{"user_id":"another234","name":"No More","company":"Trump", "event":"project.signup","user.city":"Portland","user.state":"Or", "ts":"2016-11-09"}
]' > hello.json
# replace {your model name here} with target_audience::source_audience
# generates tables
lytics segmentml --output all {your model name here}
lytics segmentml --output features {your model name here}
lytics segmentml --output predictions {your model name here}
lytics segmentml --output overview {your model name here}
# for CSV output
lytics --format csv segmentml --output all {your model name here}
# for JSON
lytics --format json segmentml --output all {your model name here}