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 2.2.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 2.2.0
File Size Uploaded Provenance Actions
needlesearchai-2.2.0.tar.gz 20.4 kB Without provenance Details for needlesearchai-2.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 46.8 kB

Release files / needlesearchai-2.2.0.tar.gz

Download URL needlesearchai-2.2.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6eaa2936a2e55612a8ff3e65a106b21c26dc66534516a357b524d13be23173f0
BLAKE2b-256 checksum
How to use checksums
b9dfd88423238915834fef22b3874dd113e8adbfac9c8d859cb029dd38eadb1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

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

Download URL needlesearchai-2.2.0-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06f2c238b7783ae6d7e418afec1d49a2f93859be3439e5382557ac72fb30fc84
BLAKE2b-256 checksum
How to use checksums
15940dd38e8566ef7da55aa25102e29c16cd999738e18d2d4593f097a2b0797e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Security for needlesearchai 2.2.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