Skip to content

Python quickstart

Get started with the Lightfield API using Python.

List one account with the Python SDK to check your API key and scope.

Install the library from PyPI:

Terminal window
pip install lightfield

An owner or admin can create an API key. See Authenticate API requests for how requests use the key.

Select the scopes your integration needs. This example needs 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:

import os
from lightfield import Lightfield
client = Lightfield(
api_key=os.environ["LIGHTFIELD_API_KEY"],
)
# list one account
accounts = client.account.list(limit=1)
print(accounts)

2. Set your API key in the environment:

Terminal window
export LIGHTFIELD_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. Inspect accounts.data for the returned records. Each record has an id and a fields map; for example, an account named Northwind Robotics has a $name field with value_type="TEXT" and value="Northwind Robotics". An empty data list is still a successful response when no readable accounts match.

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."}}

See Errors for error handling and retry guidance.