Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this package are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
[Semantic Versioning](https://semver.org/).

## [0.2.0] - 2026-11-19

### Added

- `companies.search`: `keywords` and `exclude_keywords`, matched as whole words in the company's
name, description and specialties. `Company` has `specialties` and `email_domain`.
- `people.search`: `company_keywords` and `exclude_company_keywords` (what the person's company does),
`match_headline` (title words also match the LinkedIn headline) and `priorities` with
`company_linkedin_url`: the best contacts at one company, in your order of preference, each
tagged with `priority`. `Person` has `headline`; the response has `company` with `priorities`.
- `people.count` and `companies.count` (sync and async): how many records match (`count`,
`count_capped`), using no records.
- `Usage.limits` and `Usage.resets_at`: the limits behind the remaining counts, and when each window
resets.

## [0.1.2] - 2026-11-11

### Changed
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,23 @@ Responses are dataclasses: `res.items[0].email.status`. `obj.to_dict()` returns

### People search

Filters: `title`, `seniority` (`c_level`, `vp`, `head`, `director`, `manager`, `ic`), `function` (`revenue`, `marketing`, `engineering`, `product`, `ops`, `finance`, `hr`), `company_domain`, `employees` (`"50-200"`, `"1000+"`, `"<50"`), `industry` (slugs such as `"saas"`), `country` (ISO 3166-1 alpha-2), `has_verified_email`, `max_age_days`, `exclude_stale`, `limit` (1–100, default 25) and `cursor`. A string or a list works wherever a list is accepted.
Filters: `title` (add `match_headline=True` to also match the LinkedIn headline), `seniority` (`c_level`, `vp`, `head`, `director`, `manager`, `ic`), `function` (`revenue`, `marketing`, `engineering`, `product`, `ops`, `finance`, `hr`), `company_domain`, `company_keywords` / `exclude_company_keywords` (what their company does), `employees` (`"50-200"`, `"1000+"`, `"<50"`), `industry` (slugs such as `"saas"`), `country` (ISO 3166-1 alpha-2), `has_verified_email`, `max_age_days`, `exclude_stale`, `limit` (1–100, default 25) and `cursor`. A string or a list works wherever a list is accepted.

Count before you pull, for free, and find the best contacts at one company in your order of preference:

```python
n = ls.companies.count(keywords=["clay", "gtm engineering"], exclude_keywords=["pottery"], country="US").count

res = ls.people.search(
company_domain="northwind.io",
priorities=[{"title": ["founder", "ceo"], "match_headline": True}, {"title": ["head of growth", "vp sales"]}],
limit=3,
)
for p in res.items:
print(p.priority, p.full_name, p.email.address if p.email else None)
```

`companies.search` also takes `keywords` and `exclude_keywords`: whole words in the company's name, description and specialties.

```python
res = ls.people.search(
Expand Down
2 changes: 1 addition & 1 deletion src/leadsets/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.2.0"
55 changes: 54 additions & 1 deletion src/leadsets/resources/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

from .._base import clean
from .._pagination import aiter_pages, iter_pages
from ..types import CompaniesSearchParams, CompaniesSearchResponse, Company, CompanyEnrichParams, CompanyEnrichResponse
from ..types import (
CompaniesSearchParams,
CompaniesSearchResponse,
Company,
CompanyEnrichParams,
CompanyEnrichResponse,
CountResponse,
)
from ._compat import Unpack

if TYPE_CHECKING:
Expand Down Expand Up @@ -40,6 +47,29 @@ def search(
extra_headers=extra_headers,
)

def count(
self,
*,
timeout: float | httpx.Timeout | None = None,
max_retries: int | None = None,
extra_headers: Mapping[str, str] | None = None,
**params: Unpack[CompaniesSearchParams],
) -> CountResponse:
"""POST /companies/search with ``count_only``: how many match, without returning them.

Uses no records; counts as one request. Counting stops at 10,000 (``count_capped``).
"""
return self._client.request(
"POST",
"/companies/search",
CountResponse,
body={**clean(params), "count_only": True},
idempotent=True,
timeout=timeout,
max_retries=max_retries,
extra_headers=extra_headers,
)

def search_pages(
self,
*,
Expand Down Expand Up @@ -142,6 +172,29 @@ async def search(
extra_headers=extra_headers,
)

async def count(
self,
*,
timeout: float | httpx.Timeout | None = None,
max_retries: int | None = None,
extra_headers: Mapping[str, str] | None = None,
**params: Unpack[CompaniesSearchParams],
) -> CountResponse:
"""POST /companies/search with ``count_only``: how many match, without returning them.

Uses no records; counts as one request. Counting stops at 10,000 (``count_capped``).
"""
return await self._client.request(
"POST",
"/companies/search",
CountResponse,
body={**clean(params), "count_only": True},
idempotent=True,
timeout=timeout,
max_retries=max_retries,
extra_headers=extra_headers,
)

def search_pages(
self,
*,
Expand Down
55 changes: 54 additions & 1 deletion src/leadsets/resources/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

from .._base import clean
from .._pagination import aiter_pages, iter_pages
from ..types import PeopleSearchParams, PeopleSearchResponse, Person, PersonEnrichParams, PersonEnrichResponse
from ..types import (
CountResponse,
PeopleSearchParams,
PeopleSearchResponse,
Person,
PersonEnrichParams,
PersonEnrichResponse,
)
from ._compat import Unpack

if TYPE_CHECKING:
Expand Down Expand Up @@ -40,6 +47,29 @@ def search(
extra_headers=extra_headers,
)

def count(
self,
*,
timeout: float | httpx.Timeout | None = None,
max_retries: int | None = None,
extra_headers: Mapping[str, str] | None = None,
**params: Unpack[PeopleSearchParams],
) -> CountResponse:
"""POST /people/search with ``count_only``: how many match, without returning them.

Uses no records; counts as one request. Counting stops at 10,000 (``count_capped``).
"""
return self._client.request(
"POST",
"/people/search",
CountResponse,
body={**clean(params), "count_only": True},
idempotent=True,
timeout=timeout,
max_retries=max_retries,
extra_headers=extra_headers,
)

def search_pages(
self,
*,
Expand Down Expand Up @@ -142,6 +172,29 @@ async def search(
extra_headers=extra_headers,
)

async def count(
self,
*,
timeout: float | httpx.Timeout | None = None,
max_retries: int | None = None,
extra_headers: Mapping[str, str] | None = None,
**params: Unpack[PeopleSearchParams],
) -> CountResponse:
"""POST /people/search with ``count_only``: how many match, without returning them.

Uses no records; counts as one request. Counting stops at 10,000 (``count_capped``).
"""
return await self._client.request(
"POST",
"/people/search",
CountResponse,
body={**clean(params), "count_only": True},
idempotent=True,
timeout=timeout,
max_retries=max_retries,
extra_headers=extra_headers,
)

def search_pages(
self,
*,
Expand Down
73 changes: 73 additions & 0 deletions src/leadsets/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,43 @@
# ---- Request parameters ----------------------------------------------------------------------


class PeoplePriority(TypedDict, total=False):
"""One group of titles for ``PeopleSearchParams.priorities``, best first. ``title`` is required."""

#: Titles for this priority, fuzzy-matched like ``title``.
title: _StrList
#: Titles that rule a person out of this priority, e.g. ["assistant", "intern"].
exclude_title: _StrList
#: Replaces the top-level ``seniority`` for this priority.
seniority: Seniority | Sequence[Seniority]
#: Replaces the top-level ``function`` for this priority.
function: PersonFunction | Sequence[PersonFunction]
#: Replaces the top-level ``country`` for this priority.
country: _StrList
#: Also match these titles against the LinkedIn headline.
match_headline: bool


class PeopleSearchParams(TypedDict, total=False):
#: Job titles. Fuzzy-matched: "VP Sales" also finds "Vice President, Sales".
title: _StrList
#: Also match title words against the LinkedIn headline.
match_headline: bool
seniority: Seniority | Sequence[Seniority]
function: PersonFunction | Sequence[PersonFunction]
#: Only people at these companies (domains).
company_domain: _StrList
#: With ``priorities``: the company by its LinkedIn page, instead of ``company_domain``.
company_linkedin_url: str
#: What their company does, e.g. ["clay", "gtm engineering"]: whole words in its name,
#: description and specialties.
company_keywords: _StrList
#: Leave out people whose company mentions any of these.
exclude_company_keywords: _StrList
#: Best contacts at ONE company (one ``company_domain`` or ``company_linkedin_url``): 1–10
#: groups of titles, best first. Results never repeat a person and carry ``priority``.
#: ``limit`` 1–25 (default 5); no cursor, no top-level ``title``.
priorities: Sequence[PeoplePriority]
#: Company headcount range, e.g. "50-200", "1000+" or "<50".
employees: str
#: Leadsets industry slugs, e.g. "saas".
Expand Down Expand Up @@ -103,6 +133,11 @@ class PersonEnrichParams(TypedDict, total=False):


class CompaniesSearchParams(TypedDict, total=False):
#: What the company does, e.g. ["lead generation", "appointment setting"]: whole words in its
#: name, description and specialties; any keyword matches.
keywords: _StrList
#: Leave out companies that mention any of these, e.g. ["pottery"].
exclude_keywords: _StrList
industry: _StrList
employees: str
country: _StrList
Expand Down Expand Up @@ -203,6 +238,10 @@ class Usage(Model):
scrape_units_left: int | None = None
#: True when limits could not be checked for this call.
degraded: bool | None = None
#: Paid plans: the limits behind the ``*_left_*`` numbers, e.g. ``search_records_5h``.
limits: dict[str, int] | None = None
#: Paid plans: when the oldest usage leaves each window (ISO 8601), e.g. ``search_5h``.
resets_at: dict[str, str | None] | None = None


@dataclasses.dataclass(kw_only=True)
Expand Down Expand Up @@ -232,6 +271,8 @@ class PersonCompany(Model):
company_id: str | None = None
name: str | None = None
domain: str | None = None
#: The domain the company's work emails use, when known.
email_domain: str | None = None
industry: str | None = None
employees: int | None = None
employee_range: str | None = None
Expand All @@ -244,6 +285,8 @@ class Person(Model):
first_name: str | None = None
last_name: str | None = None
title: str | None = None
#: LinkedIn headline, when known.
headline: str | None = None
seniority: Seniority | None = None
#: Finer-grained seniority, e.g. "founder" or "senior".
seniority_detail: str | None = None
Expand All @@ -258,6 +301,8 @@ class Person(Model):
personal_email: Email | None = None
#: Which filters this record matched (search results only).
match_reasons: list[str] | None = None
#: With ``priorities``: which priority found this person (1 for the first group).
priority: int | None = None
refreshed_at: str | None = None
confirmed_at: str | None = None
stale_after_at: str | None = None
Expand All @@ -266,10 +311,34 @@ class Person(Model):
sources: dict[str, FieldSource] = dataclasses.field(default_factory=dict)


@dataclasses.dataclass(kw_only=True)
class MatchedCompany(Model):
"""With ``priorities``: the company the search was scoped to."""

company_id: str | None = None
name: str | None = None
domain: str | None = None
email_domain: str | None = None
linkedin_url: str | None = None


@dataclasses.dataclass(kw_only=True)
class PeopleSearchResponse(APIResponse):
items: list[Person] = dataclasses.field(default_factory=list)
next_cursor: str | None = None
#: With ``priorities``: the company that was matched, or ``None`` when none is on file.
company: MatchedCompany | None = None
#: With ``priorities``, when no company is on file for the LinkedIn page.
note: str | None = None


@dataclasses.dataclass(kw_only=True)
class CountResponse(APIResponse):
"""``people.count`` / ``companies.count``: how many records match. Uses no records."""

count: int = 0
#: True when counting stopped at 10,000: there are at least ``count`` matches.
count_capped: bool = False


@dataclasses.dataclass(kw_only=True)
Expand All @@ -289,6 +358,8 @@ class Company(Model):
company_id: str
name: str | None = None
domain: str | None = None
#: The domain its work emails use, when known (may differ from ``domain``).
email_domain: str | None = None
linkedin_url: str | None = None
industry: str | None = None
naics: str | None = None
Expand All @@ -299,6 +370,8 @@ class Company(Model):
founded_year: int | None = None
description: str | None = None
technologies: list[str] = dataclasses.field(default_factory=list)
#: What the company says it does (LinkedIn specialties).
specialties: list[str] = dataclasses.field(default_factory=list)
match_reasons: list[str] | None = None
refreshed_at: str | None = None
confirmed_at: str | None = None
Expand Down
9 changes: 9 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ async def test_async_env_key(mock: respx.MockRouter, monkeypatch: pytest.MonkeyP
async with AsyncLeadsets() as c:
await c.usage.get()
assert route.calls[0].request.headers["authorization"] == f"Bearer {KEY}"


async def test_async_count(als: AsyncLeadsets, mock: respx.MockRouter) -> None:
route = mock.post("/v1/people/search").respond(json={"count": 7, "count_capped": False, "request_id": "r"})
res = await als.people.count(company_keywords="clay")
assert json.loads(route.calls[0].request.content) == {"company_keywords": "clay", "count_only": True}
assert res.count == 7
mock.post("/v1/companies/search").respond(json={"count": 2, "count_capped": False, "request_id": "r"})
assert (await als.companies.count(keywords="clay")).count == 2
Loading
Loading