Getting started with the Product Insights SDK for Python
[This topic is pre-release documentation and is subject to change.]
This tutorial will guide you through the process of using a Product Insights ingestion token and the Product Insights SDK for your existing Python application. You'll start seeing signals in your portal in five minutes or sooner.
For this example, picture the following scenario: you work at a car manufacturing company, and the company has just released a new car. You want to know how the car is performing, your users' demographics, and their driving habits. Product Insight allows you to achieve these goals by sending real time signals and generating valuable insights in just a few simple steps.
- Python 2.7 or 3+
- Ingestion key (see below for instructions on how to obtain)
Get an ingestion key from Product Insights portal
- From the pi.dynamics.com home screen, select your team from the left panel. If you do not already have a team, refer to Create a team.
- Add a new project to your team by selecting the + New Project button from the top right corner.
- Type in a project name in the Name field and any other text for Description. Select Create to commit the update.
- Once your project is created, select the project.
- Select Settings under your project. Your ingestion key is available under Ingestion Key.
Leave this tab open in your web browser, or copy the key to a clipboard because you will need to use it later.
Integrate the Product Insights SDK into your Python project
Download the Product Insights Python SDK.
Add the SDK to your project's site packages. This can either be done permanently or at runtime or permanently added to your
Permanently: With the specific Python interpreter you want to use activated,
cdto your project directory. Then, run
python -m easy_install pi_analytics-x.y.z.egg
At runtime: Put the following code block before any
import sys sys.path.append('/path/to/pi_analytics-x.y.z.egg')
x.y.zwith the version number found in the decompressed file.
Initialize the SDK:
from pi_analytics, import PIAnalytics, Signal from product_insights, import LogManager from datetime import datetime LogManager.initialize('your-ingestion-key') pia = PIAnalytics('your-ingestion-key')
Do a simple track signals call:
pia.track_signal(Signal('user_information')) sig = Signal('car_information')
Both indexing and
sig.properties['engine_start'] = True sig.properties['car_model'] = 'Star Car' sig.set_property('model_year', datetime.fromtimestamp(1565631527)) sig.set_property('rpm', 3000) sig.set_property('temperature', 74.3) pia.track_signal(sig)
The following types are supported for custom signal properties:
Teardown the SDK when the application closes to ensure all signals currently in the queue are sent: