A Python SDK for interacting with the Desearch API service.
Project description
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/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file desearch_py-1.2.1.tar.gz.
File metadata
- Download URL: desearch_py-1.2.1.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af137b23503699b6971730eb645f9fa94fad3ce8c516849126ed9606a02f6870
|
|
| MD5 |
1ace2fec8c2c3e57049fc4e008890132
|
|
| BLAKE2b-256 |
1df818294c7ab2c7480b51192c554802c1b9ff15da432d7010225a61d99d7a14
|
File details
Details for the file desearch_py-1.2.1-py3-none-any.whl.
File metadata
- Download URL: desearch_py-1.2.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cae651d656e838a9eb95b38c1fe998a38d4c6073a57073ba140cc76d974c68e
|
|
| MD5 |
0c879e1d3390a1f0564944096575ab36
|
|
| BLAKE2b-256 |
5cb9720566753b056f9ea8ba92f58372d7b3e93c520a4b1cd8053ceb9c92bf81
|