Python Integration

This library helps with integrating Userlist into Python applications.

See more details on the customer data structure in our general integration guide.

Installation

This library can be installed via pip:

1
pip install userlist-python

Configuration

The only required configuration is the Push API key. You can get your Push API key via the Push API settings in your Userlist account.

Configuration values can be set when creating a new push client or via environment variables. The environment takes precedence over values provided during the initialization process.

Configuration via environment variables

1
USERLIST_PUSH_KEY=401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39

Configuration during initialization

1
2
3
from userlist import Userlist

userlist = Userlist(push_key='401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39')

Usage

Before tracking user or event data, create a new push client. If you configured your push key via environment variables there’s nothing to add. Otherwise, see the example above.

1
2
from userlist import Userlist
userlist = Userlist()

Tracking Users

Creating & updating Users

1
2
3
4
5
6
7
8
9
10
11
12
13
14
user = {
    'identifier': 'user-1',
    'email': 'user@example.com',
    'properties': {
        'first_name': 'Jane',
        'last_name': 'Doe'
    }
}

userlist.users.push(user)

# Aliases
userlist.user(user)
userlist.users.create(user)

Deleting Users

1
2
userlist.users.delete('user-1')
userlist.users.delete(user)

Tracking Companies

Creating & updating Companies

1
2
3
4
5
6
7
8
9
10
11
12
13
company = {
    'identifier': 'company-1',
    'name': 'Example, Inc.',
    'properties': {
        'industry': 'Software Testing'
    }
}

userlist.companies.push(company)

# Aliases
userlist.company(company)
userlist.companies.create(company)

Deleting Companies

1
2
userlist.companies.delete('company-1')
userlist.companies.delete({'identifier': 'company-1'})

Tracking Relationships

Creating & updating Relationships

1
2
3
4
5
6
7
8
9
10
11
12
13
relationship = {
    'user': 'user-1',
    'company': 'company-1',
    'properties': {
        'role': 'admin'
    }
}

userlist.relationships.push(relationship)

# Aliases
userlist.relationship(relationship)
userlist.relationships.create(relationship)

This is equivalent to specifying the relationship on the user model:

1
2
3
4
5
6
7
8
9
10
11
user = {
    'identifier': 'user-1',
    'relationships': [{
        'company': 'company-1',
        'properties': {
            'role': 'admin'
        }
    }]
}

userlist.users.push(user)

Or specifying the relationship on the company model:

1
2
3
4
5
6
7
8
9
10
11
company = {
    'identifier': 'company-1',
    'relationships': [{
        'user': 'user-1',
        'properties': {
            'role': 'admin'
        }
    }]
}

userlist.companies.push(company)

Deleting Relationships

1
2
3
4
5
6
relationship = {
    'user': 'user-1',
    'company': 'company-1'
}

userlist.relationships.delete(relationship)

Tracking Events

1
2
3
4
5
6
7
8
9
10
11
12
13
event = {
    'name': 'project_created',
    'user': 'user-1',
    'properties': {
        'name': 'Example Project'
    }
}

userlist.events.push(event)

# Aliases
userlist.event(event)
userlist.events.create(event)

Sending Transactional Messages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
message = {
    'user': 'user-1',
    'template': 'welcome-email',
    'properties': {
        'account_name': 'Example, Inc.',
        'billing_plan': 'Pro'
    }
}

userlist.messages.push(message)

# Aliases
userlist.message(message)
userlist.messages.create(message)

Book your discovery demo

Let’s see how Userlist fits into the bigger picture of your SaaS business. You’ll learn about our automation features, integrations, proven lifecycle frameworks, and how we can help you hit your SaaS growth targets.