// City is Berlin OR Parisleadsdb.Or().City().Eq("Berlin")leadsdb.Or().City().Eq("Paris")// Combined with ANDclient.List(ctx, leadsdb.Rating().Gte(4.0), // AND leadsdb.Or().City().Eq("Berlin"), // OR leadsdb.Or().City().Eq("Paris"), // OR)
Sorting
Code
// Sort by fieldleadsdb.Sort(leadsdb.FieldName, leadsdb.Asc)leadsdb.Sort(leadsdb.FieldRating, leadsdb.Desc)leadsdb.Sort(leadsdb.FieldCreatedAt, leadsdb.Desc)// Sort by custom attributeleadsdb.Sort(leadsdb.AttrSortField("employees"), leadsdb.Desc)
from leadsdb import city, name, emailcity().eq("Berlin")name().contains("Tech")email().is_not_empty()
Number Fields
Available for: rating(), review_count()
Method
Description
eq(value)
Equals
neq(value)
Not equals
gt(value)
Greater than
gte(value)
Greater than or equal
lt(value)
Less than
lte(value)
Less than or equal
Code
from leadsdb import rating, review_countrating().gte(4.0)review_count().gt(100)
Array Fields
Available for: tags()
Method
Description
contains(value)
Array contains value
not_contains(value)
Array does not contain value
is_empty()
Array is empty
is_not_empty()
Array is not empty
Code
from leadsdb import tagstags().contains("enterprise")tags().is_not_empty()
Location
Method
Description
within_radius(lat, lon, km)
Within radius in kilometers
is_set()
Coordinates are set
is_not_set()
Coordinates are not set
Code
from leadsdb import location# Find leads within 50km of Berlinlocation().within_radius(52.52, 13.405, 50)
Custom Attributes
Use attr(name) for custom attribute filters:
Code
from leadsdb import attrattr("industry").eq("Software")attr("employees").gte(100)
OR Logic
Code
from leadsdb import or_, rating# City is Berlin OR Parisresult = client.list( rating().gte(4.0), # AND or_().city().eq("Berlin"), # OR or_().city().eq("Paris"), # OR)
Sorting
Code
from leadsdb import SortField, SortOrder, attr_sort_field# Sort by fieldresult = client.list(sort_by=SortField.NAME, sort_order=SortOrder.ASC)result = client.list(sort_by=SortField.RATING, sort_order=SortOrder.DESC)# Sort by custom attributeresult = client.list(sort_by=attr_sort_field("employees"), sort_order=SortOrder.DESC)
result = client.bulk_create([ Lead(name="Lead 1", source="import", city="Athens"), Lead(name="Lead 2", source="import", city="London"), Lead(name="Lead 3", source="import", city="Paris"),])print(f"Created: {result.success}, Failed: {result.failed}")for created in result.created: print(f"ID: {created.id} (index {created.index})")
Notes
Code
# Create a notenote = client.create_note("lead-id", "Initial contact made")# List notesnotes = client.list_notes("lead-id")# Update a notenote = client.update_note("note-id", "Updated content")# Delete a noteclient.delete_note("note-id")
Export
Code
from leadsdb import ExportFormat# Export as CSVdata = client.export(ExportFormat.CSV)with open("leads.csv", "wb") as f: f.write(data)# Export as JSONdata = client.export(ExportFormat.JSON)
from leadsdb import NotFoundError, APIErrortry: lead = client.get("non-existent-id")except NotFoundError: print("Lead not found")except APIError as e: print(f"Status: {e.status_code}, Message: {e.message}")
Exception types:
NotFoundError - Resource not found (404)
UnauthorizedError - Invalid API key (401)
ForbiddenError - Access denied (403)
RateLimitedError - Too many requests (429)
BadRequestError - Invalid request (400)
ValidationError - Client-side validation error
Using ListOptions
For more complex queries, you can use ListOptions:
Code
from leadsdb import ListOptions, city, rating, SortField, SortOrderopts = ( ListOptions() .with_limit(50) .with_sort(SortField.RATING, SortOrder.DESC) .with_filter(city().eq("Berlin")) .with_filter(rating().gte(4.0)))result = client.list(options=opts)