Skip to main content

Legichain python SDK v2

Official SDK for the existing Legichain API. KYC v2 integration and migration contains the current wire contract, check flags, asynchronous evidence and submission behavior. Version: 2.0.0; publication status is tracked separately.

from legichain import Legichain

client = Legichain(api_key="YOUR_LEGICHAIN_TOKEN")
flow = client.kyc.start({"subject_external_id": "customer-42"}, idem="customer-42-application")
# body is the current document/selfie/NFC/liveness JSON from your capture client.
receipt = flow.evidence("documents", body, idem="customer-42-front-capture-1")
flow.wait(receipt["operation_id"])
# Add the remaining configured evidence before submitting.
submission = flow.submit()

The same API is available with AsyncLegichain and await.


Legichain Python SDK

Official Python client for the Legichain AML, KYC and Travel Rule API.

pip install legichain

PyPI Python License

  • Python 3.10+
  • Sync and async clients (Legichain, AsyncLegichain)
  • Webhook HMAC verification helper
  • Typed Problem Details exceptions (RFC 7807)

Get an API key

Sign up at https://legichain.com — the Free plan ships with 1 RPS and 300 monthly credits, no card required. Once signed in:

panel.legichain.com → Settings → API Keys → New key

Keys look like lc_live_<22>.sk_live_<44> (production) or lc_test_<22>.sk_test_<44> (test mode — never spends credits, safe in CI). Store the secret half in your secret manager — the Argon2 hash means a lost key can't be recovered. See the full API guide for plans, rate limits and reference docs.


Quick start

from legichain import Legichain

cli = Legichain(api_key="lc_live_xxxxxxxx.sk_live_xxxxxxxx")

# Screen a crypto wallet
result = cli.screen_crypto(address="0x6c0bD2BB04Fda9CBfeBb8DC1208Db32a0F8a4Edd", chain="ETH")
if result["matched"]:
    for hit in result["hits"]:
        print(hit["name"], hit["risk_level"], hit["risk_score"])

# Screen a natural person
result = cli.screen_person(name="Vladimir Putin", country="RU", dob="1952-10-07")

# Generate a PDF wallet report (returns raw bytes)
pdf = cli.report_wallet(address="0x...", chain="ETH", format="pdf")
with open("report.pdf", "wb") as f:
    f.write(pdf)

# Check remaining credits
print(cli.credits()["balance"])

Async

import asyncio
from legichain import AsyncLegichain

async def main():
    async with AsyncLegichain(api_key="lc_live_....sk_live_...") as cli:
        r = await cli.screen_crypto(address="0x...", chain="ETH")
        print(r)

asyncio.run(main())

Error handling

Every non-2xx response is turned into a LegichainError carrying the RFC 7807 Problem Details payload:

from legichain import Legichain, LegichainError

cli = Legichain(api_key="...")
try:
    cli.screen_crypto(address="0xINVALID")
except LegichainError as e:
    print(e.status_code)        # 400
    print(e.code)               # "VAL_001_INVALID_ADDRESS"
    print(e.title)              # "Invalid address"
    print(e.detail)             # "Address fails checksum validation."
    print(e.problem["errors"])  # field-level errors, if any

Idempotency

Mutating endpoints accept an Idempotency-Key header. The SDK exposes this as the idem= argument. Replays within the 24 h cache window return the same response body with header Idempotent-Replay: true.

key = "checkout-2026-05-19-7f3c"
cli.screen_person(name="John Doe", idem=key)
cli.screen_person(name="John Doe", idem=key)  # served from cache

Async batch screening

For batches above a few dozen items, prefer the async variant. The call returns immediately with a job_id; the result is delivered to your registered webhook endpoint and can be polled.

job = cli.screen_batch_async([
    {"name": "John Doe", "country": "US"},
    {"address": "0xabc...", "chain": "ETH"},
])
print(job["id"], job["status"])     # queued

# Later (or via webhook screen.batch.completed):
done = cli.job(job["id"])
print(done["result"]["items"])

Webhook verification

Set up an endpoint at POST /v1/admin/webhooks (via the dashboard or API) and Legichain will send signed JSON events.

from fastapi import FastAPI, Request, HTTPException
from legichain.webhooks import verify_signature

app = FastAPI()
SECRET = "whsec_..."   # shown once at endpoint creation

@app.post("/webhooks/legichain")
async def receive(req: Request):
    body = await req.body()
    sig = req.headers.get("Legichain-Signature", "")
    if not verify_signature(body, sig, SECRET):
        raise HTTPException(400, "Bad signature")
    payload = await req.json()
    if payload["event"] == "screen.batch.completed":
        ...
    return {"ok": True}

The verifier rejects requests older than 5 minutes by default (configurable via tolerance_sec=).


Reference

Legichain(api_key, base_url="https://api.legichain.com", timeout=30.0)

Sync client. Use as a context manager to reuse a single underlying httpx.Client:

with Legichain(api_key="...") as cli:
    cli.screen_crypto(...)
    cli.screen_person(...)

Screening

Method Endpoint
screen_person(name, country, dob, document, idem) POST /v1/screen/person
screen_company(name, country, registration_number, idem) POST /v1/screen/company
screen_crypto(address, chain, idem) POST /v1/screen/crypto
screen_batch(items, idem) POST /v1/screen/batch
screen_batch_async(items, idem) POST /v1/screen/batch/async
job(job_id) GET /v1/screen/jobs/{id}

Reports

Method Endpoint
`report_wallet(address, chain, format="json" "pdf", refresh=False)`
report_person(name, country, dob, document, address, gender, format) POST /v1/reports/person
report_company(name, country, registration_number, ...) POST /v1/reports/company

When format="pdf" the client returns the raw PDF bytes.

Admin / Account

Method Endpoint
credits() GET /v1/admin/credits
usage(cursor, limit) GET /v1/admin/usage
status() GET /v1/status (no auth)

Key formats

Keys look like:

lc_live_<22>.sk_live_<44>     # production
lc_test_<22>.sk_test_<44>     # test mode — no credit charge, no webhooks fire

Test/dev keys cost zero credits and are safe to embed in CI.


Versioning & support

The SDK follows the API version (v1). Breaking API changes ship under /v2/ with a deprecation window of at least 6 months for /v1/.

Metadata

Release files for legichain 2.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 legichain 2.0.0
File Size Uploaded Provenance Actions
legichain-2.0.0.tar.gz 29.8 kB Without provenance Details for legichain-2.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 51.2 kB

Release files / legichain-2.0.0.tar.gz

Download URL legichain-2.0.0.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d4ff5931d986e2e1f8aedd5f787bd484b1db7a6d874c49d519e2e21fa48f81e8
BLAKE2b-256 checksum
How to use checksums
4626e499635e0c265aa2ed66466c432dc077a2576ea0aa951637f03884eaf0f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / legichain-2.0.0-py3-none-any.whl

Download URL legichain-2.0.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24b90b4f2b26f3c1152c0f37dcd061b56f59a8cf0d1b6346bd3b5552ab511555
BLAKE2b-256 checksum
How to use checksums
a51d5a3f4ea4c3280f5c308793bd66624581e6457e0218f35704f1a998cad1b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for legichain 2.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