This is the official Python SDK for journy.io.
Project description
journy.io Python SDK
This is the official Python SDK for journy.io.
💾 Installation
You can use the python package manager (pip
) to install the SDK:
pip install journyio-sdk
🔌 Getting started
Import
To start, first import the client.
from journyio.client import Client, Config
Configuration
To be able to use the journy.io SDK you need to generate an API key. If you don't have one you can create one in journy.io.
If you don't have an account yet, you can create one in journy.io or request a demo first.
Go to your settings, under the Connections-tab, to create and edit API keys. Make sure to give the correct permissions to the API Key.
from journyio.httpclient import HttpClientRequests
config = Config("api-key-secret")
http_client = HttpClientRequests() # If wanted, an own implementation of the HttpClient interface can be created
client = Client(http_client, config)
Methods
Get API key details
from journyio.results import Success
result = client.get_api_key_details()
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # ApiKeyDetails
print(result.permissions) # list of strings denoting the permissions
Create or update user
Note: when sending an empty value (""
) as value for a property, the property will be deleted.
from journyio.client import Properties
properties = Properties()
properties["property1"] = "value1"
result = client.upsert_user("name@domain.tld", "userId", properties)
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # None
Create or update account
Note: when sending an empty value (""
) as value for a property, the property will be deleted.
properties = Properties()
properties["property1"] = "value1"
properties["property2"] = "" # property2 will be deleted
result = client.upsert_account("accountId", "accountName", properties, ["memberId1", "memberId2"])
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # None
Link web visitor to an app user
You can link a web visitor to a user in your application when you have our snippet installed on your website. The
snippet sets a cookie named __journey
. If the cookie exists, you can link the web visitor to the user that is
currently logged in:
result = client.link("userId", "deviceId")
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # None
To get the cookies you can use:
Flask
@app.route('/...')
def method():
device_id = request.cookies.get('__journey')
if device_id:
...
...
Django
def method(request):
device_id = request.COOKIES.get('__journey')
if device_id:
...
...
Add event
from datetime import datetime
from journyio.events import Event, Metadata
metadata = Metadata()
metadata["metadata1"] = "value1"
event = Event()
.for_user_in_account("accountName", "userId", "accountId")
.happened_at(datetime.now())
.with_metadata(metadata)
result = client.add_event(event)
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # None
Get tracking snippet for a domain
from journyio.results import Success
result = client.get_tracking_snippet("www.journy.io")
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # TrackingSnippetResonse
print(result.domain) # str
print(result.snippet) # str
Handling errors
Every call will return a Success
or Failure
object. Success
objects refer to the call having succeeded (and
optionally containing data). A Failure
object refers to the API returning an error. This can be any APIError
(too
many requests, not found...). Our SDK only throws JournyExceptions
, no other exceptions should be
called. JournyExceptions
are provided with useful messages, which state where the error was made.
from journyio.utils import JournyException
try:
result = client.get_tracking_snippet("www.journy.io")
if isinstance(result, Success):
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.data) # TrackingSnippetResonse
else:
print(result.request_id) # str
print(result.calls_remaining) # int
print(result.error) # APIError
except JournyException as e:
print(e.msg) # str with error message
The request ID can be useful when viewing API logs in journy.io.
📬 API Docs
💯 Tests
To run the tests:
cd tests
pip3 install -r requirements.txt
pytest
❓ Help
We welcome your feedback, ideas and suggestions. We really want to make your life easier, so if we’re falling short or should be doing something different, we want to hear about it.
Please create an issue or contact us via the chat on our website.
🔒 Security
If you discover any security related issues, please email hans at journy io instead of using the issue tracker.
Project details
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
File details
Details for the file journyio-sdk-1.1.1.tar.gz
.
File metadata
- Download URL: journyio-sdk-1.1.1.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf9a6598f16a5be805c5862294d997c8c9ba0c8b18ce99c264b106eafd06bf4 |
|
MD5 | 343fed9ff67279038c95812212bcd722 |
|
BLAKE2b-256 | 9de7dbf88221a562c8f08b131741fd439d0436dfa379e36947dd70df00770287 |
File details
Details for the file journyio_sdk-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: journyio_sdk-1.1.1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4afd93b8633f69720664494e48a05ddc5c51075a4e46c66a335146a5ce420ebf |
|
MD5 | ffeb9cdb19ad8fdfade9f39f11c5ae99 |
|
BLAKE2b-256 | ec68915f6f6ad7f2ee4278504e365ea231dc2871d5e825cdad17bff35dd81582 |