Skip to main content

Python SDK for Neural Thinkers LAB AI Platform - OAuth v2 SSO, Sync and Async Support

Project description

Neural LAB Python SDK

PROPRIETARY SOFTWARE - ALL RIGHTS RESERVED

Python SDK for Neural LAB AI Platform APIs.

Proprietary Notice

Copyright (c) 2026 Neural Thinker | AI Engineering LTDA
CNPJ: 62.155.930/0001-71
Author: Anderson Henrique da Silva
Location: Minas Gerais, Brasil

This software is proprietary and confidential.
Unauthorized copying, distribution, or use is strictly prohibited.

Installation

pip install ntlabs

Optional Dependencies

# Full installation with all features
pip install ntlabs[full]

# Specific features
pip install ntlabs[cache]        # Redis caching
pip install ntlabs[email]        # Email templates
pip install ntlabs[export]       # PDF/Excel export
pip install ntlabs[middleware]   # FastAPI middleware
pip install ntlabs[observability] # Sentry + OpenTelemetry

For Local Development

pip install -e /path/to/neural-lab/packages/python-sdk[dev]

Quick Start

from neural_lab import NeuralLabClient

# Initialize client
client = NeuralLabClient(api_key="nl_hipo_xxx")

# Or use environment variable NEURAL_LAB_API_KEY
client = NeuralLabClient()

Available Resources

Chat (LLM)

response = client.chat.complete(
    messages=[
        {"role": "system", "content": "Você é um assistente médico."},
        {"role": "user", "content": "O que é hipertensão?"}
    ],
    model="maritaca-sabia-3",
    max_tokens=1024,
)

Email

client.email.send(
    to=["paciente@email.com"],
    subject="Confirmação de Consulta",
    html="<h1>Sua consulta foi agendada</h1>",
)

Transcription

result = client.transcribe.audio("consulta.mp3", language="pt")
print(result.text)

Government APIs

# CNPJ lookup
empresa = client.gov.cnpj("12.345.678/0001-90")

# CEP lookup
endereco = client.gov.cep("01310-100")

# CPF validation
valido = client.gov.validate_cpf("123.456.789-00")

# Portal da Transparência
contratos = client.gov.transparencia("contratos", params={"uf": "MG"})

Banco do Brasil (OAuth + PIX)

from decimal import Decimal

# OAuth - Get authorization URL
auth = client.bb.get_authorize_url(redirect_uri="https://app.com/callback")
# Redirect user to auth.authorize_url

# OAuth - Exchange code for tokens
tokens = client.bb.exchange_code(code="abc", state="xyz", redirect_uri="...")

# Get user info (CPF verified by bank)
user = client.bb.get_userinfo(tokens.access_token)
print(f"CPF: {user.cpf}, Nome: {user.nome}")

# PIX - Create charge
charge = client.bb.create_pix_charge(
    amount=Decimal("99.90"),
    description="Consulta Médica",
)
print(f"QR Code: {charge.qr_code}")

# PIX - Check status
status = client.bb.get_pix_status(charge.txid)
if status.status == "CONCLUIDA":
    print(f"Pago em: {status.paid_at}")

Medical AI (Hipócrates)

# Transcribe consultation
transcription = client.saude.transcribe(audio_file)

# Generate SOAP note
soap = client.saude.generate_soap(
    transcription=transcription.text,
    paciente={"idade": 45, "sexo": "M"},
)

Notary AI (Mercurius)

# OCR certificate
result = client.cartorio.ocr(image_file, tipo="nascimento")

# Generate deed
minuta = client.cartorio.generate_escritura(dados)

Billing

usage = client.billing.get_usage()
print(f"Total: R$ {usage.total_cost}")

Authentication (OAuth v2 with PKCE)

# Initiate OAuth flow (returns URL for redirect)
oauth = client.auth.initiate_oauth_v2(
    provider="github",  # or "google"
    redirect_uri="https://myapp.com/auth/callback",
    product="hipocrates",
)
# Redirect user to: oauth["authorization_url"]

# After callback, claim the session (frontend receives sid + sig in URL)
session = client.auth.claim_session(
    session_id="sess_xxx",
    signature="hmac_xxx",
)
print(f"Token: {session['access_token']}")
print(f"User: {session['user']['email']}")

# Validate a session
validation = client.auth.validate_session(
    session_id="sess_xxx",
    product="hipocrates",
)
if validation["valid"]:
    print(f"User: {validation['user']['email']}")

# Check SSO (for cross-product auth)
sso = client.auth.check_sso(product="mercurius")
if sso["has_valid_session"]:
    print("User already authenticated via SSO")

# Refresh tokens (with rotation)
new_tokens = client.auth.refresh_v2(
    refresh_token="old_refresh_token",
    session_id="sess_xxx",
)

# Logout (single session)
client.auth.revoke_session(session_id="sess_xxx")

# Global logout (all sessions)
client.auth.revoke_session(revoke_all=True)

SSO Cross-Product Navigation

# Create ticket for navigating to another product
ticket = client.auth.create_sso_ticket(target_product="mercurius")
# Redirect to: https://mercurius.app/auth?sso_ticket={ticket['ticket']}

# On target product: exchange ticket for session
session = client.auth.exchange_sso_ticket(
    ticket="ticket_xxx",
    target_product="mercurius",
)

Environment Variables

Variable Description
NEURAL_LAB_API_KEY API key (nl_hipo_xxx, nl_merc_xxx, nl_poli_xxx)
NEURAL_LAB_API_URL API URL (default: production)

Error Handling

from neural_lab import (
    NeuralLabClient,
    AuthenticationError,
    RateLimitError,
    InsufficientCreditsError,
    APIError,
)

try:
    response = client.chat.complete(messages=[...])
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except InsufficientCreditsError:
    print("Add more credits")
except APIError as e:
    print(f"API error: {e}")

License

Proprietary Software

Copyright (c) 2026 Neural Thinker | AI Engineering LTDA

All rights reserved. This software and its documentation are proprietary and confidential. No part of this software may be reproduced, distributed, or transmitted in any form or by any means without the prior written permission of Neural Thinker | AI Engineering LTDA.

For licensing inquiries: contato@neural-lab.com.br

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

ntlabs-1.3.0.tar.gz (179.9 kB view details)

Uploaded Source

Built Distribution

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

ntlabs-1.3.0-py3-none-any.whl (177.7 kB view details)

Uploaded Python 3

File details

Details for the file ntlabs-1.3.0.tar.gz.

File metadata

  • Download URL: ntlabs-1.3.0.tar.gz
  • Upload date:
  • Size: 179.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ntlabs-1.3.0.tar.gz
Algorithm Hash digest
SHA256 444321b3e372a2e0cb2107fa9f06249dcaf6ac49db59de51f2812bb8396f4d86
MD5 f96205d83739ed79dba850215889a911
BLAKE2b-256 5c51d5727101ce19138553087230eef182061892a96f78ec4c11b95eb927e64c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ntlabs-1.3.0.tar.gz:

Publisher: publish-sdk.yml on NeuralThinkersLab/neural-lab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ntlabs-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: ntlabs-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 177.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ntlabs-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7be077fd429c7d5770d818c14b5fdb47fc95b0da27dd28e90b6505771da2bcf
MD5 77544665f28723f1f0e77a1c8a5a5c9d
BLAKE2b-256 40640e33545e959086d6ed67c647810c71ae730b65c04538c409a6a5d8d08747

See more details on using hashes here.

Provenance

The following attestation bundles were made for ntlabs-1.3.0-py3-none-any.whl:

Publisher: publish-sdk.yml on NeuralThinkersLab/neural-lab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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