Skip to main content

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

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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for needlesearchai 3.0.0
File Size Uploaded Provenance Actions
needlesearchai-3.0.0.tar.gz 20.6 kB Without provenance Details for needlesearchai-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for needlesearchai 3.0.0
File Interpreter ABI Platform Actions
needlesearchai-3.0.0-py3-none-any.whl Python 3 none any Details for needlesearchai-3.0.0-py3-none-any.whl

Total release size: 47.3 kB

Release files / needlesearchai-3.0.0.tar.gz

Download URL needlesearchai-3.0.0.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f69106abc5599e58ff1395ac701aa288091d1cd3b7cf4fd8402527311008181f
BLAKE2b-256 checksum
How to use checksums
0bc76a8ead2f071ab3ec86aa83f2eb63cb1d5ce31a91617ad20a58afc3579fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Release files / needlesearchai-3.0.0-py3-none-any.whl

Download URL needlesearchai-3.0.0-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79621bce9fc90e34b18f555a16899c82efbfe88e22ec8761a0b34fa5960e6347
BLAKE2b-256 checksum
How to use checksums
076e79361c6188e050efd25bed64deb31eaaf14e076d4b5b1b860c054de81e3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Security for needlesearchai 3.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page