Skip to main content

This is the official Python SDK for journy.io.

Project description

journy.io

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-sdk 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-sdk 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-sdk 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-sdk 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-sdk 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-sdk 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-sdk 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

API reference

💯 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

journyio-sdk-0.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

journyio_sdk-0.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file journyio-sdk-0.0.1.tar.gz.

File metadata

  • Download URL: journyio-sdk-0.0.1.tar.gz
  • Upload date:
  • Size: 10.4 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

Hashes for journyio-sdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3ebf9ea36c68b75047004dd32086cf29fb9e99a00541512a3e8fcd7238f9221f
MD5 d9d2c5410ff20ce8478ef416e5a6b685
BLAKE2b-256 17ed13541fdc5abc5a64e63a9ae76212e06ca605a4044a3142ca7f5348762256

See more details on using hashes here.

File details

Details for the file journyio_sdk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: journyio_sdk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 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

Hashes for journyio_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 743e6846449ccab04e2fd238361164497edeea3112737f6e73011f364aeb28e5
MD5 800912780aa3b78738cd41f2bba8eeb2
BLAKE2b-256 28575291897983fc41f148bb6f5a7f3112048561c9ecf9f20a091102a451d5e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page