Connect to Signals within a notebook using the Signals Python SDK
The first step is to set up your Signals connection. Follow the instructions in the Signals connection documentation to enable Signals through Snowplow Console.
Once your connection is set up, gather the required credentials as described in the connection credentials section.
Set up your Jupyter notebook environment
You can use either Google Colab or a local Jupyter notebook environment for this tutorial.
If you want to skip ahead, you can make use of the following notebook that contains all the Python code you'll need for this tutorial:
Using Google Colab
You can use the provided notebook, or create your own. To create a new notebook, open a new notebook at Google Colab.
You'll need to add credentials as Colab secrets. Click the key icon in the left sidebar, and add the required secrets:
SP_API_URL: your Signals API URLSP_API_KEY: your API keySP_API_KEY_ID: your API key IDSP_ORG_ID: your Snowplow Console organization ID
When you run the notebook, it will ask for access to the secrets. Choose to grant access.
If you're using your own notebook, follow these steps:
- Install the Signals Python SDK:
%pip install snowplow-signals
- Load your credentials in the notebook:
from google.colab import userdata
import os
os.environ["SP_API_URL"] = userdata.get('SP_API_URL')
os.environ["SP_API_KEY"] = userdata.get('SP_API_KEY')
os.environ["SP_API_KEY_ID"] = userdata.get('SP_API_KEY_ID')
os.environ["SP_ORG_ID"] = userdata.get('SP_ORG_ID')
Using local Jupyter
Navigate into your working directory and environment, then follow these steps:
- Install Jupyter and the Signals SDK:
pip install jupyter snowplow-signals python-dotenv
- Create a
.envfile in your working directory with your credentials:
SP_API_URL=your_signals_api_url
SP_API_KEY=your_api_key
SP_API_KEY_ID=your_api_key_id
SP_ORG_ID=your_organization_id
- Start Jupyter notebook:
jupyter notebook
- In your notebook, load the environment variables:
from dotenv import load_dotenv
load_dotenv()
Connect to Signals
Now you're ready to connect to your Signals instance using the Python SDK.
from snowplow_signals import Signals
import os
sp_signals = Signals(
api_url=os.environ["SP_API_URL"],
api_key=os.environ["SP_API_KEY"],
api_key_id=os.environ["SP_API_KEY_ID"],
org_id=os.environ["SP_ORG_ID"],
)
You're now ready to start defining attributes and interventions in Signals.