Skip to main content

Legal data integrations (CourtListener, citations, case law) for the Matrx ecosystem

Project description

matrx-legal

Legal data integrations for the Matrx ecosystem. Standalone-installable; first-class inside aidream.

Initial provider: CourtListener (REST API v4, bulk S3 dumps, webhooks). Designed to host additional sources (Westlaw, Lexis, Justia, CAP, Caselaw Access Project) behind a uniform interface.

What it does

  • Async client for CourtListener REST API v4 with token-bucket throttling, cursor pagination, retry, and 429/Retry-After handling.
  • Pydantic models for every public response shape.
  • Optional ORM persistence (matrx-orm) for cached opinions, dockets, courts, citations.
  • Optional bulk ingest from CourtListener's free quarterly S3 dumps via Postgres COPY.
  • Optional RAG indexing of opinion full-text (host injects the embedder).
  • Optional FastAPI streaming endpoints (host wires them up).
  • AI tool callables ready to register with matrx-ai's tools registry.

Quick start

import asyncio
from matrx_legal.courtlistener import CourtListenerClient

async def main():
    async with CourtListenerClient() as client:
        async for hit in client.search(q="miranda v arizona", type="o", page_size=20):
            print(hit.case_name, hit.absolute_url)

asyncio.run(main())

Set COURTLISTENER_API_TOKEN in your environment.

Host integration

import matrx_legal
from my_app.settings import settings
from my_app.db import LegalOpinion, LegalDocket  # subclassed from matrx_legal.orm

matrx_legal.configure(
    settings=settings,
    db_models={"LegalOpinion": LegalOpinion, "LegalDocket": LegalDocket, ...},
    file_handler_class=FileManager,
    embedder=my_embedder,
)

Standalone testing

uv run pytest packages/matrx-legal/tests

Tests must pass with only matrx-utils installed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrx_legal-0.1.5.tar.gz (64.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matrx_legal-0.1.5-py3-none-any.whl (72.9 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page