desearch-py
Official async Python SDK for the Desearch API.
desearch-py is a thin aiohttp client for the Desearch public API. It wraps search, X, and crawl endpoints behind a single async client class and returns pydantic models for most successful responses. The package metadata currently reports version 1.2.1 and requires Python 3.9+.
Package purpose
Use this SDK when you want to call Desearch from Python without hand-rolling HTTP requests, auth headers, or response parsing. The repository ships:
- an async client in
desearch_py/api.py - typed models and enums in
desearch_py/models.py - lightweight Sphinx scaffolding in
docs/ - packaging metadata in both
pyproject.tomlandsetup.py
Two names matter:
- package on PyPI and in Poetry metadata:
desearch-py - import path in Python code:
desearch_py
Quick Start
Install
pip install desearch-py
Run a basic AI search
import asyncio
from desearch_py import Desearch
async def main() -> None:
async with Desearch(api_key="your_api_key") as client:
result = await client.ai_search(
prompt="What happened in Bittensor this week?",
tools=["web", "twitter", "reddit"],
count=10,
)
print(result)
asyncio.run(main())
Read optional response cost metadata
Default calls continue to return the original typed payload only:
result = await client.ai_search(
prompt="What happened in Bittensor this week?",
tools=["web", "twitter"],
)
print(result.text)
When you want per-request cost visibility, opt in with include_metadata=True:
response = await client.ai_search(
prompt="What happened in Bittensor this week?",
tools=["web", "twitter"],
include_metadata=True,
)
print(response.data.text)
print(response.metadata.cost_usd)
print(response.metadata.usage_count)
print(response.metadata.service)
print(response.metadata.currency)
The SDK reads metadata from the same API response headers (X-Desearch-Cost-Usd, for example 0.00015, plus X-Desearch-Usage-Count, X-Desearch-Service, and X-Desearch-Currency). Missing or malformed numeric headers are exposed as None instead of breaking a successful API call.
Reuse the client manually
import asyncio
from desearch_py import Desearch
async def main() -> None:
client = Desearch(api_key="your_api_key")
try:
tweets = await client.x_search(query="desearch", sort="Latest", count=5)
print(tweets)
finally:
await client.close()
asyncio.run(main())
Requirements
Dependencies declared in source:
- Python
>=3.9(pyproject.toml,setup.py) aiohttp >=3.8pydantic >=2.0
setup.py also lists typing-extensions as an install dependency.
Commands
| Task | Command | Notes |
|---|---|---|
| Install published package | pip install desearch-py |
For consumers |
| Install local repo editable | pip install -e . |
Uses setup.py |
| Install local repo with Poetry | poetry install |
Uses pyproject.toml |
| Build distributables | poetry build |
Produces package artifacts |
| Publish package | ./publish.sh |
Repository script |
| Run tests | poetry run python -m unittest discover -s tests -v |
Uses the stdlib unittest runner |
| Build Sphinx docs | make -C docs html |
Requires Sphinx dev deps |
A minimal unittest suite covers response metadata behavior. There is still no dedicated lint or format command configured in the repo.
Tech stack
- Python 3.9+
aiohttpfor async HTTPpydanticv2 models for typed responses- Poetry + setuptools metadata side by side
- Sphinx scaffolding for docs
Supported SDK surface
AI search
ai_searchai_web_links_searchai_x_links_search
X / Twitter endpoints
x_searchx_posts_by_urlsx_post_by_idx_posts_by_userx_post_retweetersx_user_postsx_user_repliesx_post_repliesx_trends
Web endpoints
web_searchweb_crawl
Typed exports
The package re-exports the async client plus enums and models from desearch_py.models, including Tool, WebTool, DateFilter, ResultType, Sort, ResponseData, DesearchCostMetadata, DesearchResponse, TwitterScraperTweet, WebSearchResponse, WebSearchResultsResponse, XLinksSearchResponse, XRetweetersResponse, XUserPostsResponse, and XTrendsResponse.
Architecture overview
The SDK is intentionally small.
desearch_py/api.pycontains theDesearchclient and every HTTP method.desearch_py/models.pycontains enums and permissivepydanticschemas.desearch_py/__init__.pyre-exports the public API.
Key design decisions visible in code:
- the HTTP session is created lazily on first use
- auth is sent as
Authorization: <api_key>with noBearerprefix - most requests share a single helper with a fixed 120 second timeout
- successful responses can opt in to a
DesearchResponsewrapper with parsed cost metadata from response headers x_posts_by_urlsandweb_crawlbypass that shared helper and make direct requests, but still support the metadata wrapper- some endpoints fall back to raw
dictvalues instead of failing model parsing ai_searchalways sends"streaming": False
Usage notes
Use async with when possible
async with Desearch(api_key="your_api_key") as client:
results = await client.web_search(query="Desearch API")
This is the safest pattern because it guarantees the underlying aiohttp.ClientSession gets closed.
Expect mixed return types on some methods
The following methods may return a typed object on success or a raw dict when the API shape does not match the local parser exactly:
ai_searchx_searchx_posts_by_userx_user_repliesx_post_replies
If your app depends on strict typing, add runtime checks before dereferencing attributes.
Override the base URL for non-production environments
client = Desearch(
api_key="your_api_key",
base_url="https://staging-api.desearch.ai",
)
Repo boundaries
Always:
- treat this repo as the Python SDK only
- verify docs against
desearch_py/api.py,desearch_py/models.py,pyproject.toml, andsetup.py - document current behavior, even when it exposes limitations
Never:
- describe unsupported streaming or retry behavior as implemented
- assume generated files in
docs/_build/are the source of truth - confuse this repo with
desearch.js,desearch-public-api, ordesearch-console
Additional docs
- Feature inventory
- Architecture notes
- Known issues
- ADR: current behavior is the documentation source of truth
Links
- Desearch: https://desearch.ai
- Console: https://console.desearch.ai
- API docs: https://desearch.ai/docs/api-reference/
Metadata
Release files for desearch-py 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| desearch_py-1.2.1.tar.gz | 15.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| desearch_py-1.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.7 kB
Release files / desearch_py-1.2.1.tar.gz
| Download URL | desearch_py-1.2.1.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af137b23503699b6971730eb645f9fa94fad3ce8c516849126ed9606a02f6870
|
|
BLAKE2b-256 checksum How to use checksums |
1df818294c7ab2c7480b51192c554802c1b9ff15da432d7010225a61d99d7a14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / desearch_py-1.2.1-py3-none-any.whl
| Download URL | desearch_py-1.2.1-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7cae651d656e838a9eb95b38c1fe998a38d4c6073a57073ba140cc76d974c68e
|
|
BLAKE2b-256 checksum How to use checksums |
5cb9720566753b056f9ea8ba92f58372d7b3e93c520a4b1cd8053ceb9c92bf81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for desearch-py 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.