Package: journyio-sdk
journy.io Python SDKThis is the official Python SDK forjourny.io.💾 InstallationYou can use the python package manager (pip) to install the SDK:pipinstalljournyio-sdk🔌 Getting startedImportTo start, first import the client.fromjournyio.clientimportClient,ConfigConfigurationTo 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
injourny.io.If you don't have an account yet, you can create one
injourny.ioorrequest a demo first.Go to your settings, under theConnections-tab, to create and edit API keys. Make sure to give the correct permissions
to the API Key.fromjournyio.httpclientimportHttpClientRequestsconfig=Config("api-key-secret")http_client=HttpClientRequests()# If wanted, an own implementation of the HttpClient interface can be createdclient=Client(http_client,config)MethodsGet API key detailsfromjournyio.resultsimportSuccessresult=client.get_api_key_details()ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# ApiKeyDetailsprint(result.permissions)# list of strings denoting the permissionsCreate or update user💡 A user ID should be a robust, static, unique identifier that you recognize a user by in your own systems. Because these IDs are consistent across a customer’s lifetime, you should include a user ID in identify calls as often as you can. Ideally, the user ID should be a database ID.💡 journy.io does not recommend using simple email addresses or usernames as user ID, as these can change over time. journy.io recommends that you use static IDs instead, so the IDs never change. When you use a static ID, you can still recognize the user in your analytics tools, even if the user changes their email address.💡 The propertiesfull_name,first_name,last_name,phoneandregistered_atwill be used for creating contacts in destinations like Intercom, HubSpot, Salesforce, ...fromjournyio.clientimportPropertiesfromjournyio.user_identifiedimportUserIdentifiedfromdatetimeimportdatetimeuser=UserIdentified("userId","name@domain.tld")# oruser=UserIdentified.by_user_id("userId")# oruser=UserIdentified.by_email("name@domain.tld")properties=Properties()properties["full_name"]="John Doe"properties["first_name"]="John"properties["last_name"]="Doe"properties["phone"]="123"properties["is_admin"]=Trueproperties["registered_at"]=datetime.now()properties["age"]=26properties["array_of_values"]=["value1","value2"]properties["key_with_empty_value"]=""properties["this_property_will_be_deleted"]=Noneresult=client.upsert_user(user,properties)ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneDelete userfromjournyio.clientimportPropertiesfromjournyio.user_identifiedimportUserIdentifiedfromdatetimeimportdatetimeuser=UserIdentified("userId","name@domain.tld")# oruser=UserIdentified.by_user_id("userId")# oruser=UserIdentified.by_email("name@domain.tld")result=client.delete_user(user)ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneCreate or update account💡 An account ID should be a robust, static, unique identifier that you recognize an account by in your own systems. Ideally, the account ID should be a database ID.💡 The propertiesname,mrr,planandregistered_atwill be used to create companies in destinations like Intercom, HubSpot, Salesforce, ...fromjournyio.account_identifiedimportAccountIdentifiedfromjournyio.user_identifiedimportUserIdentifiedfromdatetimeimportdatetimeaccount=AccountIdentified("accountId","www.domain.tld")# oraccount=AccountIdentified.by_account_id("accountId")# oraccount=AccountIdentified.by_domain("www.domain.tld")properties=Properties()properties["name"]="ACME, Inc"properties["mrr"]=399properties["plan"]="Pro"properties["registered_at"]=datetime.now()properties["is_paying"]=Trueproperties["array_of_values"]=["value1","value2"]properties["key_with_empty_value"]=""properties["this_property_will_be_deleted"]=Noneresult=client.upsert_account(account,properties)ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneDelete accountfromjournyio.account_identifiedimportAccountIdentifiedfromjournyio.user_identifiedimportUserIdentifiedfromdatetimeimportdatetimeaccount=AccountIdentified("accountId","www.domain.tld")# oraccount=AccountIdentified.by_account_id("accountId")# oraccount=AccountIdentified.by_domain("www.domain.tld")result=client.delete_account(account)ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneAdd user(s) to an accountfromjournyio.account_identifiedimportAccountIdentifiedfromjournyio.user_identifiedimportUserIdentifiedaccount=AccountIdentified.by_account_id("accountId")user1=UserIdentified.by_user_id("memberId1")user2=UserIdentified.by_email("member2@domain.tld")result=client.add_users_to_account(account,[user1,user2])ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneRemove user(s) from an accountWhen removing a user, the user will still be stored in journy.io, but marked as "removed".fromjournyio.account_identifiedimportAccountIdentifiedfromjournyio.user_identifiedimportUserIdentifiedaccount=AccountIdentified.by_domain("www.domain.tld")user1=UserIdentified.by_user_id("memberId1")user2=UserIdentified.by_email("member2@domain.tld")result=client.remove_users_from_account(account,[user1,user2])ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneLink web visitor to an app userYou 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:fromjournyio.user_identifiedimportUserIdentifieduser=UserIdentified("userId","name@domain.tld")# oruser=UserIdentified.by_user_id("userId")# oruser=UserIdentified.by_email("name@domain.tld")result=client.link(user,"deviceId")ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneTo get the cookies (for thedeviceId) you can use:Flask@app.route('/...')defmethod():device_id=request.cookies.get('__journey')ifdevice_id:......Djangodefmethod(request):device_id=request.COOKIES.get('__journey')ifdevice_id:......Add eventfromdatetimeimportdatetimefromjournyio.eventsimportEvent,Metadatafromjournyio.account_identifiedimportAccountIdentifiedfromjournyio.user_identifiedimportUserIdentifiedaccount=AccountIdentified("accountId","www.domain.tld")user=UserIdentified("userId","name@domain.tld")metadata=Metadata()metadata["metadata1"]="value1"event=Event().for_user_in_account("settings_updated",user,account).happened_at(datetime.now()).with_metadata(metadata)result=client.add_event(event)ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# NoneGet tracking snippet for a domainfromjournyio.resultsimportSuccessresult=client.get_tracking_snippet("www.journy.io")ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# TrackingSnippetResonseprint(result.domain)# strprint(result.snippet)# strHandling errorsEvery call will return aSuccessorFailureobject.Successobjects refer to the call having succeeded (and
optionally containing data). AFailureobject refers to the API returning an error. This can be anyAPIError(too
many requests, not found...). Our SDK only throwsJournyExceptions, no other exceptions should be
called.JournyExceptionsare provided with useful messages, which state where the error was made.fromjournyio.utilsimportJournyExceptiontry:result=client.get_tracking_snippet("www.journy.io")ifisinstance(result,Success):print(result.request_id)# strprint(result.calls_remaining)# intprint(result.data)# TrackingSnippetResonseelse:print(result.request_id)# strprint(result.calls_remaining)# intprint(result.error)# APIErrorexceptJournyExceptionase:print(e.msg)# str with error messageThe request ID can be useful when viewing API logs
injourny.io.📬 API DocsAPI reference💯 TestsTo run the tests:cdtests
pipinstall-rrequirements.txt
pipinstall-Upytest
pythonscripts/createversion.py0.0.0
pytest❓ HelpWe 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.🔒 SecurityIf you discover any security related issues, please email security at journy io instead of using the issue tracker.