Skip to content

Using the Rose Python Library

This an overview of the functions you can use to view data on Rose through Python. If you haven't already, please install the Rose Python Library first.

There are eight basic functions in Rose that communicate between Rose and Python to store data so that users or companies can always come back to it and be able to specifically access who, where, what, when, and how the data has been changed.

The eight functions can be divided into two groups: push and pull; each group contains four functions.

From Rose to Python:

  • pull
  • pull_logic
  • run_query

From Python to Rose:

  • push
  • push_logic
  • push_query

DOWNLOAD our demo Jupyter Notebook.

Import the Library

Use this import statement in order to use Rose functions. Before you can push and pull data you need to login with your rose.ai username and password.

from rose_wrapper.rose import Rose
rose = Rose()
rose.login(username, password)

.login(username, password)

Establishes a connect with a user's account on rose.ai. We recommend importing a config file with your Rose username and password.

Parameters

  • username (str): Your rose.ai username or email address
  • password (str): Your rose.ai password

Example of logging in:

rose.login("username", "password")

.push(rosecode, metas, values, overwrite, data_type)

Allows you to push either a map or a timeseries dataset to rose.ai

Parameters

  • rosecode (str): The name of rosecode you want to push. This will be the identifier for the dataset. ex: "my.test.timeseries"
  • metas (dataframe): The metadata information for your dataset
    • Will be visible in the details menu
    • must consist of two columns one for meta tags and the other for the values
  • values (dataframe): The values for the dataset.
  • overwrite (boolean):
    • True: If dataset exists the old will be replaced with the new values
    • False: Dataset will only update with new values (not replace old values, even if they have changed)
  • data_type (str - optional):
    • timeseries (default): dataset will be treated as a timeseries dataset
    • map: dataset will be treated as and pushed as a map dataset

Example of pushing a timeseries:

from rose_wrapper.rose import Rose
import pandas as pd
import datetime

rose = Rose()
rose.login(username, password)

dates = [datetime.datetime(2019, 1, 1), datetime.datetime(2019, 1, 2)]
values = [100,101]

my_data_values = pd.DataFrame(index=dates, data={'values': values})

meta_tags = ['units', 'frequency']
meta_values = ['dollars', 'daily']

my_data_metas = pd.DataFrame(index = meta_tags, data={'values': meta_values})

rose.push('test.timeseries', metas=my_data_metas, values=my_data_values, overwrite=True)
Note: you will need to install the pandas python package for this example

Example of pushing a map:

from rose_wrapper.rose import Rose
import pandas as pd
import datetime

rose.login(username, password)

values = pd.DataFrame({'names':['john', 'jane'], 'age':[32, 35]})
metas = pd.DataFrame(index=['source'], data={'values': ['SQL']})

rose.push('test.map', metas=metas, values=values, data_type='map')

.pull(rosecode, as_pandas, output)

The pull function is used to pull map or timeseries data from rose.ai

Parameters:

  • rosecode (str): The rosecode you want to pull
  • as_pandas (boolean) optional:
    • True (default): Dataset will return as a pandas dataframe
    • False: Dataset will return as a dictionary
  • output (str - optional)
    • values (default): will return only the values for the rosecode entered
    • metas: will return only the metadata of the dataset
    • dataset_info: will return only information like owner, id...etc
    • all : will return values, metas, and dataset_info

Example of pulling a timeseries:

from rose_wrapper.rose import Rose
import pandas as pd
import datetime

rose = Rose()
rose.login(username, password)

my_data, my_data_metas, my_data_values = rose.pull('test.timeseries', output='all' )
print(my_data_values)

Example of pulling a map:

from rose_wrapper.rose import Rose

import pandas as pd
import datetime

rose = Rose()
rose.login(username, password)

my_data, my_data_metas, my_data_values = rose.pull('test.map', output='all' )
print(my_data_values)

.push_logic(rosecode, logic)

Parameters:

  • rosecode (str): The name of the new rosecode that will point to the old rosecode with logic applied.
  • logic (str): The original rosecode and transformations.

Example of pushing logic:

from rose_wrapper.rose import Rose

rose = Rose()
rose.login(username, password)

rose.push_logic(code = 'test.data.z', logic='test.data:z')

.pull_logic(rosecode)

Parameters:

  • rosecode (str): The rosecode of the logic to pull

Example of pulling logic:

from rose_wrapper.rose import Rose

rose = Rose()
rose.login(username, password)

rose.pull_logic('test.data.z')

.run_query(query, connection)

Parameters:

  • query (str): The sql query to run
  • connection (str): The database connection in Rose to run the query with

Example of running a query:

from rose_wrapper.rose import Rose

rose = Rose()
rose.login(username, password)

rose.run_query('SELECT * FROM demo_db.demo_table LIMIT 10', 'demo.db')

.push_query(code, query, connection)

Parameters:

  • code (str): The new rosecode for the query
  • query (str): The sql query to run
  • connection (str): The database connection in Rose to run the query with

Example of pushing a query:

from rose_wrapper.rose import Rose

rose = Rose()
rose.login(username, password)

rose.push_query('rose.demo.query', 'SELECT * FROM demo_db.demo_table LIMIT 10', 'demo.db')