Zelighted API Python Client
Project description
zelighted
Python client for the Zelighted NPS/CSAT survey API.
Installation
pip install zelighted
With optional .env file support:
pip install "zelighted[dotenv]"
Configuration
Option 1: Environment variables
export ZELIGHTED_API_URL=https://api.zeb.mx/api/v1/ # production
# export ZELIGHTED_API_URL=https://api-stg.zeb.mx/api/v1/ # staging
# export ZELIGHTED_API_URL=http://localhost:8001/api/v1/ # local dev (default)
export ZELIGHTED_API_KEY=your_api_key
zelighted reads these on import. ZELIGHTED_API_URL defaults to http://localhost:8001/api/v1/ if unset.
Option 2: zelighted.configure()
import zelighted
zelighted.configure(
api_base_url="https://api.zeb.mx/api/v1/",
api_key="YOUR_API_KEY",
)
If python-dotenv is installed, configure() loads .env automatically before applying values.
Option 3: Per-client configuration
from zelighted import Client
client = Client(
api_key="YOUR_API_KEY",
api_base_url="https://api.zeb.mx/api/v1/",
)
Pass client=client to any resource call to use a specific client instance.
Usage
Person
import zelighted
# Create and schedule a survey immediately
person = zelighted.Person.create(email="user@example.com")
# Create with a 60-second delay
person = zelighted.Person.create(email="user@example.com", delay=60)
# Create without scheduling a survey
person = zelighted.Person.create(email="user@example.com", send=False)
# Create with properties
person = zelighted.Person.create(
email="user@example.com",
name="Jane Doe",
properties={"customer_id": 42, "plan": "pro"},
delay=30,
)
# List all people (auto-paginated)
for person in zelighted.Person.list().auto_paging_iter():
print(person.id)
# Delete by id, email, or phone
zelighted.Person.delete(id=42)
zelighted.Person.delete(email="user@example.com")
zelighted.Person.delete(phone_number="+14155551212")
SurveyResponse
import zelighted
# Create
response = zelighted.SurveyResponse.create(person=person.id, score=9)
response = zelighted.SurveyResponse.create(person=person.id, score=5, comment="Good service.")
# Retrieve
response = zelighted.SurveyResponse.retrieve("123")
# Update
response.score = 10
response.save()
# List
page1 = zelighted.SurveyResponse.all()
page2 = zelighted.SurveyResponse.all(page=2)
expanded = zelighted.SurveyResponse.all(expand=["person"])
desc = zelighted.SurveyResponse.all(order="desc")
import datetime, pytz
tz = pytz.timezone("America/Chicago")
filtered = zelighted.SurveyResponse.all(
since=tz.localize(datetime.datetime(2024, 1, 1)),
until=tz.localize(datetime.datetime(2024, 3, 31)),
)
Metrics
import zelighted
metrics = zelighted.Metrics.retrieve()
metrics = zelighted.Metrics.retrieve(trend="123")
import datetime, pytz
tz = pytz.timezone("America/Chicago")
metrics = zelighted.Metrics.retrieve(
since=tz.localize(datetime.datetime(2024, 1, 1)),
until=tz.localize(datetime.datetime(2024, 3, 31)),
)
Unsubscribe
import zelighted
# Unsubscribe a person
zelighted.Unsubscribe.create(person_email="user@example.com")
# List unsubscribed people
page1 = zelighted.Unsubscribe.all()
page2 = zelighted.Unsubscribe.all(page=2)
Bounce
import zelighted
page1 = zelighted.Bounce.all()
page2 = zelighted.Bounce.all(page=2)
SurveyRequest
import zelighted
# Delete pending survey requests for a person
zelighted.SurveyRequest.delete_pending(person_email="user@example.com")
AutopilotMembership
import zelighted
# Email autopilot
zelighted.AutopilotMembership.forEmail().create(person_email="user@example.com")
for member in zelighted.AutopilotMembership.forEmail().list().auto_paging_iter():
print(member)
zelighted.AutopilotMembership.forEmail().delete(person_email="user@example.com")
# SMS autopilot
zelighted.AutopilotMembership.forSms().create(person_phone_number="+14155551212")
for member in zelighted.AutopilotMembership.forSms().list().auto_paging_iter():
print(member)
zelighted.AutopilotMembership.forSms().delete(person_phone_number="+14155551212")
zelighted.AutopilotMembership.forSms().delete(person_id=42)
Pagination
Use auto_paging_iter() to iterate through all pages automatically:
import zelighted
# Handle rate limits manually
people = zelighted.Person.list()
while True:
try:
for person in people.auto_paging_iter():
print(person.id)
break
except zelighted.errors.TooManyRequestsError as e:
import time
time.sleep(e.retry_after)
# Or let the client handle rate limits for you
for person in zelighted.Person.list(auto_handle_rate_limits=True).auto_paging_iter():
print(person.id)
Error Handling
import zelighted
from zelighted.errors import (
ZelightedError,
AuthenticationError,
TooManyRequestsError,
)
try:
metrics = zelighted.Metrics.retrieve()
except AuthenticationError:
print("Invalid API key.")
except TooManyRequestsError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds.")
except ZelightedError as e:
print(f"API error: {e}")
Release Process
- Bump
__version__inzelighted/__init__.py(e.g.5.1.0→5.2.0) - Add a matching entry to
CHANGELOG.md - Push to
master - CI automatically: runs tests → detects version bump → builds package → uploads to PyPI → creates GitHub Release with changelog notes → pushes git tag
v{version}
Prerequisite:
PYPI_API_TOKENmust be set as a repository secret in GitHub → Settings → Secrets and variables → Actions.
Contributing
git clone https://github.com/luuna-tech/Zelighted-python.git
cd Zelighted-python
pip install -e ".[dotenv]"
pip install pytest pytz tzlocal
pytest test/ -v
Branch naming: spec/SPEC-XXX for spec work, fix/short-description for bug fixes.
- Fork the repo
- Create your branch (
git checkout -b spec/SPEC-XXX) - Run the tests (
pytest test/ -v) - Commit your changes
- Push and open a Pull Request against
master
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zelighted-5.1.1.tar.gz.
File metadata
- Download URL: zelighted-5.1.1.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dd578cadd050d36464ca0f6fa222a0a72caf82b29b82de15c8a616c53c7f2c8
|
|
| MD5 |
614d7ca68ccfa9c493af8e0e5e6d90fd
|
|
| BLAKE2b-256 |
1eed547fda850013b97397d9bbf94919e234ee582a5750a4a2a3740e1d86bffd
|
File details
Details for the file zelighted-5.1.1-py3-none-any.whl.
File metadata
- Download URL: zelighted-5.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
547d4e521d5d6aeecd489dee5fab7cb04192577ebf3f8c8d5cfd192108298692
|
|
| MD5 |
7a098678b871003099cc7c848388d000
|
|
| BLAKE2b-256 |
6aeed4fd1df710ae145f3ed730a1a00ac6391b6a79ae8b044df7d2577d8c3398
|