Skip to main content

Zelighted API Python Client

Project description

zelighted

Python client for the Zelighted NPS/CSAT survey API.

CI PyPI version Python versions License


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

  1. Bump __version__ in zelighted/__init__.py (e.g. 5.1.05.2.0)
  2. Add a matching entry to CHANGELOG.md
  3. Push to master
  4. 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_TOKEN must 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.

  1. Fork the repo
  2. Create your branch (git checkout -b spec/SPEC-XXX)
  3. Run the tests (pytest test/ -v)
  4. Commit your changes
  5. Push and open a Pull Request against master

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zelighted-5.1.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zelighted-5.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file zelighted-5.1.2.tar.gz.

File metadata

  • Download URL: zelighted-5.1.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zelighted-5.1.2.tar.gz
Algorithm Hash digest
SHA256 0fcabd5c240ace63a4861d61f75e2429f2c28628c7fdee9653c7fb6cb671b12d
MD5 a2c0102b70895e182ad5b5299d151ba7
BLAKE2b-256 8c4d821ff7bddf908c07247f7e67306debb4c48382ff88512fa7bfd90131a9b9

See more details on using hashes here.

File details

Details for the file zelighted-5.1.2-py3-none-any.whl.

File metadata

  • Download URL: zelighted-5.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zelighted-5.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39345cfac3a66f4a7764ed23594b698afc111720f6b646d5db0bf0632d97eda1
MD5 3c4b3434f67fe331147577f5f701a14f
BLAKE2b-256 fd468aacbcdb4b61cc5f80fea726dd97c1c03cd0ab86e0916718fc786c95f262

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page