UID2 SDK for Python
Project description
UID2 SDK for Python
The UID 2 Project is subject to Tech Lab IPR’s Policy and is managed by the IAB Tech Lab Addressability Working Group and Privacy & Rearc Commit Group. Please review the governance rules.
This document includes:
Who Is this SDK for?
This SDK simplifies integration with UID2 for DSPs and UID Sharers, as described in UID2 Integration Guides.
Requirements
This SDK supports Python 3.6 and above.
Install
The SDK can be installed using pip.
pip install uid2-client
Usage for DSPs
Connect to the UID2 service, refresh the encryption keys, and then use the keys to decrypt an advertising token, to arrive at the corresponding advertising ID: For examples of usage for DSPs, see sample_client.py and sample_auto_refresh.py
from uid2_client import Uid2ClientFactory
# for UID2 (for EUID use EuidClientFactory)
client = Uid2ClientFactory.create('https://prod.uidapi.com', 'my-auth-token', 'my-secret-key')
client.refresh_keys()
advertising_token = 'AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A=='
decrypted_token = client.decrypt(advertising_token)
print(decrypted_token.uid2)
Usage for Sharers
A UID2 sharer is a participant that wants to share UID2s or EUIDs with another participant. Raw UID2s must be encrypted into UID2 tokens before sending them to another participant. For examples of usage, see sample_sharing.py and sample_auto_refresh.py
from uid2_client import Uid2ClientFactory
# for UID2 (for EUID use EuidClientFactory)
client = Uid2ClientFactory.create('https://prod.uidapi.com', 'my-auth-token', 'my-secret-key')
client.refresh_keys()
Senders:
- Call the following:
encrypted = client.encrypt(raw_uid)
- If encryption was successful, send the token
encrypted.uid2
to the receiver.
Receivers:
- Call the following:
decrypted = client.decrypt(uid_token)
- If decryption was successful, use the token
decrypted.uid2
.
Development
First, build the Docker image with Python 3.6 and all dev dependencies. This is required for all subsequent commands. Run the following:
make docker
Run unit tests:
make test
Build a bdist wheel:
make wheel
Get access to an interactive shell within the Python 3.6 Docker image:
make shell
Example Usage
To run all the example applications:
make examples BASE_URL=https://prod.uidapi.com AUTH_KEY=my-auth-key SECRET_KEY=my-secret-key \
AD_TOKEN=AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A== \
RAW_UID=JCqmlLXpbbu/jTdpB2a1cNAVs8O72eMXPaQzC9Ic9mE=
Alternatively, you can run specific examples:
make example_client BASE_URL=https://prod.uidapi.com AUTH_KEY=my-auth-key SECRET_KEY=my-secret-key \
AD_TOKEN=AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A==
make example_auto_refresh BASE_URL=https://prod.uidapi.com AUTH_KEY=my-auth-key SECRET_KEY=my-secret-key \
AD_TOKEN=AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A==
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for uid2_client-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb600c6169d7e3fb4356fd314711362aa173a305a0234ab1eeadf25d922d51e2 |
|
MD5 | b1014e4bd2d92970eb69c50c25e15bf1 |
|
BLAKE2b-256 | 99fbd9ad0ef78d4616c29765a3262e7bddff02d2b98f56fdc32210c4462eb6c4 |