Python quickstart
Get started with the Lightfield API using Python.
List one account with the Python SDK to check your API key and scope.
Installation
Section titled “Installation”Install the library from PyPI:
pip install lightfieldGet an API key
Section titled “Get an API key”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.
Make your first request
Section titled “Make your first request”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 accountaccounts = client.account.list(limit=1)print(accounts)2. Set your API key in the environment:
export LIGHTFIELD_API_KEY="sk_lf_..."3. Run the script from your terminal (from the same directory as the file):
python quickstart.pyThe 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.
Next steps
Section titled “Next steps”- 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.