Set up your Signals connection
The first step is to set up your Signals connection. Follow the instructions in the Signals connection documentation for your chosen deployment method:
- Snowplow Console: enable Signals through Snowplow Console if you have a Snowplow account
- Signals Sandbox: deploy a Sandbox instance to experiment without a Snowplow account
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:
- Snowplow Console
- Signals Sandbox
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
SP_API_URL: your Profiles API URLSP_SANDBOX_TOKEN: your Sandbox Token
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:
- Snowplow Console
- Signals Sandbox
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')
from google.colab import userdata
import os
os.environ["SP_API_URL"] = userdata.get('SP_API_URL')
os.environ["SP_SANDBOX_TOKEN"] = userdata.get('SP_SANDBOX_TOKEN')
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:
- Snowplow Console
- Signals Sandbox
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
SP_API_URL=your_profiles_api_url
SP_SANDBOX_TOKEN=your_sandbox_token
- 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.
- Snowplow Console
- Signals Sandbox
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"],
)
from snowplow_signals import SignalsSandbox
import os
sp_signals = SignalsSandbox(
api_url=os.environ["SP_API_URL"],
sandbox_token=os.environ["SP_SANDBOX_TOKEN"],
)
The SignalsSandbox class is specifically designed for Sandbox environments. For production Snowplow deployments, you would use the Signals class instead, which requires API keys.
You're now ready to start defining attributes and interventions in Signals.