NeedleSearch Python SDK
Client for the NeedleSearch API — semantic search, grounded chat and deep research over your own document corpus.
Install
pip install needlesearchai
Note the name: plain needlesearch on PyPI is an abandoned registration with no files behind it — it is not us, and installing it fails.
Or straight from the repository, to track dev ahead of a release:
pip install "git+https://github.com/Legal-Analytics-Inc/AI-LegalSearch#subdirectory=sdk/python"
Quick start
from needlesearchai import NeedleSearch
ns = NeedleSearch(api_key="nsk_...") # base_url defaults to https://chat.needlesearch.ai/v1
# Is it us or is it you? Needs no key.
print(ns.status().status)
# Semantic search, optionally with an AI overview over the matches
results = ns.search("termination clauses")
answer = ns.search("How long is the notice period?", include_overview=True)
# Browse. Prefer iterate() over offset paging: it follows the cursor, which
# is stable while other people are uploading.
for item in ns.items.iterate():
print(item.name, item.status)
# Deep research. The async form survives proxies that cut long connections.
job = ns.jobs.create("What are the risks in this contract?", item_ids=[doc_id])
print(ns.jobs.wait(job.id).answer)
Document status
item.status is the published lifecycle — queued, processing, ready, failed, cancelled — and is the one to branch on. item.status_detail carries the pipeline’s internal stage; it is useful in a log or a support ticket and carries no compatibility promise.
item = ns.items.get(doc_id)
if item.is_ready:
text = ns.items.content(doc_id)["markdown"]
elif item.is_terminal:
print("gave up:", item.error)
Errors
Every failure raises a subclass of NeedleSearchError carrying the API’s machine-readable code:
from needlesearchai import NeedleSearchError, RateLimitError
try:
ns.search("...")
except RateLimitError as e:
time.sleep(e.retry_after)
except NeedleSearchError as e:
print(e.error_code, e.status_code) # e.g. "insufficient_scope", 403
SpendLimitError (daily_spend_limit, resets at 00:00 UTC) is not retried by the client; ServiceUnavailableError (capacity_exhausted, queue_unavailable, platform_spend_limit) carries retry_after when the server sent one.
Webhooks
Verify every delivery before trusting it. verify_signature does the two things a hand-rolled check usually gets wrong — a constant-time comparison, and rejecting a replayed capture by its timestamp:
from needlesearchai import verify_signature
# `raw_body` must be the bytes as received; re-serializing the parsed JSON
# changes them and the signature will not match.
if not verify_signature(secret, raw_body, request.headers["X-NeedleSearch-Signature"]):
return 400
Retries
Send an Idempotency-Key on anything you might retry — research runs and webhook registrations both cost something you do not want to pay twice:
job = ns.jobs.create("...", idempotency_key="batch-2026-02-01-run-7")
hook = ns.webhooks.create("https://example.com/hook", idempotency_key="hook-v1")
License
MIT
Metadata
Release files for needlesearchai 3.0.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 | Actions |
|---|---|---|---|---|
| needlesearchai-3.0.1.tar.gz | 21.4 kB | Without provenance | Details for needlesearchai-3.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| needlesearchai-3.0.1-py3-none-any.whl | Python 3 | none | any | Details for needlesearchai-3.0.1-py3-none-any.whl |
Total release size: 48.8 kB
Release files / needlesearchai-3.0.1.tar.gz
| Download URL | needlesearchai-3.0.1.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48d3b6856c85dbba1db1b2a63b8d7447acc715c4a6d39183bfcfce5be75ca2a1
|
|
BLAKE2b-256 checksum How to use checksums |
bb1864239927ca12ced5d2337640a178f843b4b64e87ad94cb8670a5242216ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / needlesearchai-3.0.1-py3-none-any.whl
| Download URL | needlesearchai-3.0.1-py3-none-any.whl |
|---|---|
| Size | 27.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80223361185857aa13260303cceb3079ba025dd8d641fa65d975aac74fa8dcf7
|
|
BLAKE2b-256 checksum How to use checksums |
bae78cfb116cd2f4eecaca18bf1e14c9f19600a436ac9f4a96e5d8950dd2228f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for needlesearchai 3.0.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.