SlicingDice Documentation

SlicingDice API Docs

Welcome to the SlicingDice API documentation. You'll find comprehensive guides and documentation to help you start working with SlicingDice as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Documentation

Python 2

Python 2 client/SDK for SlicingDice

You can use the SlicingDice's Python client/SDK to rapidly start inserting and querying your data, without having to handle with all the API HTTP requests yourself.

Installing the client

In order to install the Python client, you only need to use pip or visit this page .

pip install pyslicer --extra-index-url=https://packagecloud.io/slicingdice/clients/pypi/simple

Source code

SlicingDice's Python client/SDK source code is available on Github .

Build Status: CircleCI


Tests and Examples

At the Python client/SDK Github repository, you will find examples of data insertion and queries with their respective expected result messages. You take advantage of all these examples to test the client and also learn how to use it.


Using the client

SlicingDice class encapsulates logic for sending requests to the API. Its methods are thin layers around the API endpoints, so their parameters and return values are JSON-like dict and lists objects with the same syntax as the API endpoints.

from pyslicer import SlicingDice

# Configure the client
client = SlicingDice(master_key='API_KEY')

# Creating a column
column_data = {
    'name': 'Age',
    'api-name': 'age',
    'description': 'User age',
    'type': 'integer',
    'storage': 'latest-value'
}
client.create_column(column_data)

# Inserting data
insert_data = {
    'user1@slicingdice.com': {
        'age': 22
    }
}
client.insert(insert_data)

# Querying data
query_data = {
    'query-name': 'users-between-20-and-40',
    'query': [
        {
            'age': {
                'range': [
                    20,
                    40
                ]
            }
        }
    ]
}
print(client.count_entity(query_data))

API Keys

API keys are configured with the client constructor, as presented in the example below.

from pyslicer import SlicingDice

# Configure client with master API key
client = SlicingDice(master_key='MASTER_API_KEY')

# Configure client with read API key
client = SlicingDice(read_key='READ_API_KEY')

# Configure client with write API key
client = SlicingDice(write_key='WRITE_API_KEY')

# Configure client with custom API key
client = SlicingDice(custom_key='CUSTOM_API_KEY')

Constructor

__init__(self, 
         master_key=None, 
         write_key=None, 
         read_key=None, 
         custom_key=None, 
         use_ssl=True, 
         timeout=60)
  • master_key (str) - Master API Key to used to authenticate requests on SlicingDice API.
  • write_key (str) - Write API Key to used to authenticate requests on SlicingDice API.
  • read_key (str) - Read API Key to used to authenticate requests on SlicingDice API.
  • custom_key (str) - Custom API Key to used to authenticate requests on SlicingDice API.
  • use_ssl (bool) - Define if it should verify SSL for HTTPS requests. (when set to False, all operations but insert() become unavailable)
  • timeout (int) - Amount of time, in seconds, to wait for results for each request.

Methods

  • get_database() - Get current database, identified by the given API key. This method corresponds to a GET request at /database.
from pyslicer import SlicingDice
slicingdice = SlicingDice('MASTER_API_KEY')
print(slicingdice.get_database())
  • get_columns() - Get all created columns, both active and inactive ones organized by table. This method corresponds to a GET request at /column.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.get_columns())
  • create_column(json_data) - Create a new column. This method corresponds to a POST request at /column.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

insert_data = [
    {
        "type": "string",
        "storage": "latest-value",
        "api-name": "state",
        "name": "User State",
        "description": "State where the user lives"
    }, 
    {
        "type": "integer",
        "storage": "latest-value",
        "api-name": "age",
        "name": "User Age"
    }
]
print(slicingdice.create_column(insert_data))
  • insert(json_data) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

insert_data = {
    "UUID-01": {
        "table": "users",
        "age": 25,
        "name": "Jeff",
        "clicks": [
            {
                "date": "2017-05-26T12:54:12Z",
                "value": "Add to Cart"
            }, 
            {
                "date": "2017-05-31T10:22:10Z",
                "value": "Pay Now"
            }, 
            {
                "date": "2017-06-03T17:05:25Z",
                "value": "Support"
            }
        ]
    },
    "auto-create": [
        "table", 
        "column"
    ]
}

print(slicingdice.insert(insert_data))
  • exists_entity(ids, table=None) - Verify which entities exist in a table (uses default table if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

table = "users"
query_data = [
        "user1@slicingdice.com", 
        "user2@slicingdice.com", 
        "user3@slicingdice.com", 
        "user4@slicingdice.com", 
        "user5@slicingdice.com"
]

print(slicingdice.exists_entity(query_data, table=table))
  • count_entity_total(tables=[]) - Count the number of stored entities in given tables (or in all tables by default). This method corresponds to a POST request at /query/count/entity/total.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.count_entity_total())
  • count_entity(json_data) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = [
    {
        "table": "users",
        "query-name": "jeff-user-clicked-to-pay",
        "bypass-cache": True,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }, 
            "and", 
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ]
    }
]

print(slicingdice.count_entity(query_data))
  • count_event(json_data) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = [
    {
        "query": [
            {
                "actions": {
                    "equals": "visited-page",
                    "between": [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ],
        "query-name": "visited-page-events"
    }
]

print(slicingdice.count_event(query_data))
  • top_values(json_data) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "name-contains-eff": {
        "table": "users",
        "contains": [
            "eff"
        ],
        "name": 3
    }
}

print(slicingdice.top_values(query_data))
  • aggregation(json_data) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "filter": [
        {
            "country": {
                "equals": "USA"
            }
        }
    ],
    "query": [
        {
            "purchased-products": 2,
            "between": [
                "2017-05-16T00:00:00Z", 
                "2017-06-04T00:00:00Z"
            ]
        }
    ]
}

print(slicingdice.aggregation(query_data))
  • get_saved_queries() - Get all saved queries. This method corresponds to a GET request at /query/saved.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.get_saved_queries())
  • create_saved_query(json_data) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "type": "count/entity",
    "name": "my-saved-query",
    "table": "users"
}

print(slicingdice.create_saved_query(query_data))
  • update_saved_query(query_name, json_data) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "type": "count/entity",
    "table": "users"
}

print(slicingdice.update_saved_query("my-saved-query", query_data))
  • get_saved_query(query_name) - Execute a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.get_saved_query("my-saved-query"))
  • delete_saved_query(query_name) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.delete_saved_query("my-saved-query"))
  • result(json_data) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "limit": 3,
    "columns": [
        "city", 
        "state"
    ]
}

print(slicingdice.result(query_data))
  • score(json_data) - Retrieve stored values as well as their relevance for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/score.
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }, 
        "or", 
        {
            "gender": {
                "equals": "male"
            }
        }, 
        "or", 
        {
            "age": {
                "range": [
                    18, 
                    25
                ]
            }
        }
    ],
    "limit": 3,
    "columns": [
        "city", 
        "state"
    ]
}

print(slicingdice.score(query_data))
  • sql(statement) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query statement

from pyslicer import SlicingDice
client = SlicingDice('MASTER_OR_READ_API_KEY')
query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49"
print(client.sql(query))

Insert statement

from pyslicer import SlicingDice
client = SlicingDice('MASTER_OR_READ_API_KEY')
query = "INSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)"
print(client.sql(query))

Python 2

Python 2 client/SDK for SlicingDice