Skip to content
Getting started

Python quickstart

Get started with the Lightfield API using Python.

This guide walks you through making your first request to the Lightfield API using the official Python SDK.

Install the library from PyPI:

Terminal window
pip install lightfield

An API key can be created in Lightfield settings (admin only).

When creating the key, select the scopes your integration needs.

For the example below, you’ll need accounts:read.

Create a client and list one account to verify your key and scope.

1. Create a new file (e.g. quickstart.py) and paste in:

from lightfield import Lightfield
client = Lightfield(
api_key="My API Key",
)
# list one account
accounts = client.account.list(limit=1)
print(accounts)

2. Replace "My API Key" with your actual API key (sk_lf_...).

3. Run the script from your terminal (from the same directory as the file):

Terminal window
python quickstart.py

The client returns an AccountListResponse object. A successful response looks like:

AccountListResponse(
data=[
Data(
id="id",
created_at="created_at",
fields={
"foo": DataFields(value="string", value_type="value_type"),
},
http_link="http_link",
relationships={
"foo": DataRelationships(
cardinality="cardinality",
object_type="object_type",
values=["string"],
),
},
)
],
object="list",
total_count=1,
)

With limit=1 you get at most one account. To fetch more results, use limit and offset — see List methods for pagination. The full API is in the Python API Reference.

Error handling: The SDK raises typed exceptions you can catch. If your API key is wrong you’ll see:

lightfield.AuthenticationError: Error code: 401 - {'error': {'type': 'unauthorized', 'message': 'Invalid API key.'}}

If the key is valid but missing the required scope:

lightfield.PermissionDeniedError: Error code: 403 - {'error': {'type': 'forbidden', 'message': "Token does not have the 'accounts:read' scope."}}

For more on error responses and how to handle them, see Errors.

  • Objects in Lightfield — Overview of object types (accounts, contacts, opportunities, and more) and how they relate.
  • Python API Reference — Full API reference with Python code examples.
  • Rate limits — Request limits and how to handle 429 responses.
  • Idempotency — Safe retries for create and update operations.