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.0 and requires Python 3.9+.
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
pip install desearch-pyimport 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())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())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.
| 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 |
| Build Sphinx docs | make -C docs html |
Requires Sphinx dev deps |
There are currently no dedicated test, lint, or format commands configured in the repo. This is an accurate reflection of the current source tree, not an omission in this README.
- Python 3.9+
aiohttpfor async HTTPpydanticv2 models for typed responses- Poetry + setuptools metadata side by side
- Sphinx scaffolding for docs
ai_searchai_web_links_searchai_x_links_search
x_searchx_posts_by_urlsx_post_by_idx_posts_by_userx_post_retweetersx_user_postsx_user_repliesx_post_repliesx_trends
web_searchweb_crawl
The package re-exports the async client plus enums and models from desearch_py.models, including Tool, WebTool, DateFilter, ResultType, Sort, ResponseData, TwitterScraperTweet, WebSearchResponse, WebSearchResultsResponse, XLinksSearchResponse, XRetweetersResponse, XUserPostsResponse, and XTrendsResponse.
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
x_posts_by_urlsandweb_crawlbypass that shared helper and make direct requests- some endpoints fall back to raw
dictvalues instead of failing model parsing ai_searchalways sends"streaming": False
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.
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.
client = Desearch(
api_key="your_api_key",
base_url="https://staging-api.desearch.ai",
)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
- Feature inventory
- Architecture notes
- Known issues
- ADR: current behavior is the documentation source of truth
- Desearch: https://desearch.ai
- Console: https://console.desearch.ai
- API docs: https://desearch.ai/docs/api-reference/