Python SDK
pip install klozeoRequires Python 3.10+.
Quick start
Section titled “Quick start”from klozeo import ( Klozeo, Lead, text_attr, number_attr, city, rating, SortField, SortOrder)
client = Klozeo("sk_live_your_api_key")
# Create a leadlead = client.leads.create(Lead( name="Acme Corp", source="website", city="Berlin", email="contact@acme.com", attributes=[ text_attr("industry", "Software"), number_attr("employees", 500), ]))
# List with filtersleads = client.leads.list( filters=[city.eq("Berlin"), rating.gte(4.0)], sort_by=SortField.RATING, sort_order=SortOrder.DESC, limit=20,)
# Iterate all pages automaticallyfor lead in client.leads.iterate(filters=[city.eq("Berlin")]): print(lead.name)
# Export to CSVimport csv, iodata = client.leads.export(format="csv")reader = csv.DictReader(io.StringIO(data))Handling errors
Section titled “Handling errors”from klozeo import KlozeoError, RateLimitError, AuthError, NotFoundError
try: lead = client.leads.create(Lead(name="Acme", source="web"))except RateLimitError as e: print(f"Rate limited. Retry after {e.retry_after}s")except AuthError: print("Invalid or revoked API key")except NotFoundError: print("Lead not found")except KlozeoError as e: print(f"API error {e.status}: {e.message}")