---
title: Introduction to the Swimlane REST API and Python Driver
slug: user-guide-10x/introduction-to-the-swimlane-rest-api-and-python-driver
docTags: 
createdAt: 2025-12-12T21:35:10.814Z
---

# Background

The Swimlane platform provides a REST API with numerous endpoints to allow solution developers to harness and extend the platform's automation and orchestration power. Developers can use any programming tool with an HTTP library/capability. Or, they can use the Python library known as the Swimlane Driver, a client library that can reduce the effort required to implement custom solutions.

# REST API

Here's a sample script for connecting to Swimlane and creating a new record in a chosen application:

:::BlockQuote
import requests
from urlparse import urljoin

s = requests.Session()

\# Authenticate
host = 'HOST'
base\_url = 'https\://&#x7B;0}'.format(host)
creds = \{'userName': 'USERNAME', 'password': 'PASSWORD'}
resp = s.post(urljoin(base\_url, 'api/user/login'), json=creds)

json\_content = resp.json()
token = json\_content.pop('token', None)
headers = \{
&#x20;   'Authorization': 'Bearer \{}'.format(token)
}
s.headers.update(headers)

\# Retrieve the chosen application
resp = s.get(urljoin(base\_url, 'api/app'))
apps = resp.json()
app\_obj = None
for app in apps:
&#x20;   if app\['name'] == 'Event':
&#x20;       app\_obj = app
&#x20;       break

\# Create a new record in the chosen application. First find pertinent field ID values in order to make correct field value assignments.
name\_field\_id = None
msg\_field\_id = None
for field in app\_obj\['fields']:
&#x20;   if field\['name'] == 'Event Name':
&#x20;       name\_field\_id = field\['id']
&#x20;   if field\['name'] == 'Event Message':
&#x20;       msg\_field\_id = field\['id']
&#x20;      &#x20;
record = \{
&#x20;   'applicationId': app\_obj\['id'],
&#x20;   'values': \{
&#x20;       '$type': 'System.Collections.Generic.Dictionary\`2\[\[System.String, mscorlib],\[System.Object, mscorlib]], mscorlib',
&#x20;       name\_field\_id: 'demo security event 1',
&#x20;       msg\_field\_id: 'this event is for demonstration purposes'
&#x20;       }
&#x20;   }

result = s.post(urljoin(base\_url, 'api/app/' + app\_obj\['id'] + '/record'), json=record)

print result
:::

Here is a sample script for fetching an existing record, modifying it, and persisting the changes:

:::BlockQuote
import requests
from urlparse import urljoin
import json

s = requests.Session()

\# Authenticate
host = 'HOST'
base\_url = 'https\://&#x7B;0}'.format(host)
creds = \{'userName': 'USER', 'password': 'PASSWORD'}
resp = s.post(urljoin(base\_url, 'api/user/login'), json=creds)

json\_content = resp.json()
token = json\_content.pop('token', None)
headers = \{
&#x20;   'Authorization': 'Bearer \{}'.format(token)
}
s.headers.update(headers)

\# Retrieve the chosen application
resp = s.get(urljoin(base\_url, 'api/app'))
apps = resp.json()
app\_obj = None
for app in apps:
&#x20;   if app\['name'] == 'Event':
&#x20;       app\_obj = app
&#x20;       break

\# Find chosen field ID
msg\_field\_id = None
for field in app\_obj\['fields']:
&#x20;   if field\['name'] == 'Event Message':
&#x20;       msg\_field\_id = field\['id']
&#x20;       break

\# Retrieve an existing record
result = s.get(urljoin(base\_url, 'api/app/' + app\_obj\['id'] + '/record/tracking/EV1-1'))
\#print result
rec = result.json()
\#print json.dumps(rec, sort\_keys=True, indent=4, separators=(",", ": "))

\# Update the record
rec\['values']\[msg\_field\_id] = 'I\\'ve been updated!!!'


\# Persist the alteration to the record
result = s.put(urljoin(base\_url, 'api/app/' + app\_obj\['id'] + '/record/' + rec\['id']), json=rec)

print result
:::

Here is the same script made more optimal by using HTTP PATCH rather than HTTP PUT to avoid REST API-centric race conditions that can arise when two scripts are attempting to operate on the same record within the same span of time. The use of PATCH reduces the chances of harmful, colliding alterations to the record.

:::BlockQuote
import requests
from urlparse import urljoin
import json

s = requests.Session()

\# Authenticate
host = 'HOST'
base\_url = 'https\://&#x7B;0}'.format(host)
creds = \{'userName': 'USER', 'password': 'PASSWORD'}
resp = s.post(urljoin(base\_url, 'api/user/login'), json=creds)

json\_content = resp.json()
token = json\_content.pop('token', None)
headers = \{
&#x20;   'Authorization': 'Bearer \{}'.format(token)
}
s.headers.update(headers)

\# Retrieve the chosen application
resp = s.get(urljoin(base\_url, 'api/app'))
apps = resp.json()
app\_obj = None
for app in apps:
&#x20;   if app\['name'] == 'Event':
&#x20;       app\_obj = app
&#x20;       break

\# Find chosen field IDs
name\_field\_id = None
msg\_field\_id = None
tracking\_field\_id = None
for field in app\_obj\['fields']:
&#x20;   if field\['name'] == 'Event Name':
&#x20;       name\_field\_id = field\['id']
&#x20;   if field\['name'] == 'Event Message':
&#x20;       msg\_field\_id = field\['id']
&#x20;   if field\['name'] == 'Tracking Id':
&#x20;       tracking\_field\_id = field\['id']

\# Retrieve an existing record
result = s.get(urljoin(base\_url, 'api/app/' + app\_obj\['id'] + '/record/tracking/EV1-1'))
print result
rec = result.json()
\#print json.dumps(rec, sort\_keys=True, indent=4, separators=(",", ": "))

\# Update the record
rec\['values']\[msg\_field\_id] = 'I\\'ve been updated!!!'
rec\['values'].pop(tracking\_field\_id, None) # The PATCH endpoint will throw error with a 400 response if the Tracking Id is present as a field value.
rec\['values'].pop(name\_field\_id, None)
\#print json.dumps(rec, sort\_keys=True, indent=4, separators=(",", ": "))

\# Persist the alteration to the record
result = s.patch(urljoin(base\_url, 'api/app/' + app\_obj\['id'] + '/record/' + rec\['id']), json=rec)

print result # Print result.text if you want to see the error message that accompanies an HTTP 400 response.
:::


Swimlane Driver
===============

The above examples help to convey the power and appeal of the Swimlane Driver. Compare the above examples with their Driver equivalents below:

:::BlockQuote
from swimlane import Swimlane

\# Connect Swimlane client
host = 'HOST'
base\_url = 'https\://&#x7B;0}'.format(host)
swimlane = Swimlane(base\_url, 'USER', 'PASSWORD', verify\_ssl=False)

\# Retrieve App by name
app = swimlane.apps.get(name='Event')

\# Create new Record
new\_record = app.records.create(\*\*\{
&#x20;   'Event Name': 'demo security event 1',
&#x20;   'Event Message': 'this event is for demonstration purposes'
})
:::

and

:::BlockQuote
from swimlane import Swimlane

\# Connect Swimlane client
host = 'HOST'
base\_url = 'https\://&#x7B;0}'.format(host)
swimlane = Swimlane(base\_url, 'USERNAME', 'PASSWORD', verify\_ssl=False)

\# Retrieve App by name
app = swimlane.apps.get(name='Event')

\# Fetch existing record
record = app.records.get(tracking\_id='EV1-4')

\# Modify record
record\['Event Message'] = 'I\\'ve been updated!!!'

\# Persist the modification
record.patch()
:::


Conclusion
==========

When authoring Python scripts for the Swimlane Platform follow these guidelines:

1. When authoring scripts that will run outside of the Platform, use the Swimlane Driver whenever possible and fall back on the unwrapped REST API when necessary.
2. When authoring scripts that will run inside of the Platform, use the Task API first, and then fall back on the Driver and/or REST API when necessary.
