Access all your Lynara data from Python. Automate your processes, sync your tools, and build custom integrations.
pip install lynara-erp3 steps to start using the Lynara SDK.
pip install lynara-erpfrom lynara import Lynara
# --- Production ---
client = Lynara(
url="https://api.lynara.ai",
api_key="lnr_live_xxxxxxxxxxxx",
company_id="your-company-uuid"
)
# --- Test / Sandbox ---
test_client = Lynara(
url="https://api.lynara.ai",
api_key="lnr_test_xxxxxxxxxxxx",
company_id="your-company-uuid"
)# Read your customers
customers = client.catalog.customers.list()
for c in customers:
print(c["name"], c["contact_email"])
# Count customers
total = client.catalog.customers.count()
print(f"Total: {total}")
# Search employees
results = client.rh.employees.list(search="Ali")
print(f"Found: {results.total_count}")
# Create an invoice
invoice = client.sales.invoices.create({
"customer_id": "uuid-du-client",
"number": "FAC-2026-001",
"sequence_year": 2026,
"currency": "EUR",
"total_ht": 1500.00,
"total_tax": 300.00,
"total_ttc": 1800.00
})
print(f"Facture {invoice['number']} created!")
# Read CRM leads
hot_leads = client.crm.leads.list(filters={"rating": "hot"})
for lead in hot_leads:
print(lead["customer_name"], lead["estimated_value"])A real script that fetches data from 5 modules to generate a CSV performance report.
"""
Full project: ERP -> Dashboard sync
This script fetches data from Lynara to generate
a monthly sales performance report.
"""
from lynara import Lynara
import csv
from datetime import datetime
# --- Production ---
client = Lynara(
url="https://api.lynara.ai",
api_key="lnr_live_xxxxxxxxxxxx",
company_id="your-company-uuid"
)
# --- Or in test mode (sandbox) ---
# client = Lynara(
# url="https://api.lynara.ai",
# api_key="lnr_test_xxxxxxxxxxxx",
# company_id="your-company-uuid"
# )
# ═══════════════════════════════════════════
# 1. Fetch this month's invoices
# ═══════════════════════════════════════════
invoices = client.sales.invoices.list(
filters={"status": "posted"},
limit=500
)
print(f"Invoices found: {len(invoices)}")
total_revenue = sum(float(inv["total_ttc"]) for inv in invoices)
total_unpaid = sum(
float(inv["total_ttc"]) - float(inv["amount_paid"])
for inv in invoices
if inv["status"] != "paid"
)
# ═══════════════════════════════════════════
# 2. Analyze CRM pipeline
# ═══════════════════════════════════════════
leads = client.crm.leads.list(filters={"status": "qualified"})
opportunities = client.crm.opportunities.list(filters={"status": "open"})
pipeline_value = sum(float(opp["amount"] or 0) for opp in opportunities)
hot_leads_count = len([l for l in leads if l.get("rating") == "hot"])
# ═══════════════════════════════════════════
# 3. Critical stock levels
# ═══════════════════════════════════════════
stock_levels = client.inventory.stock_levels.list()
settings = client.inventory.product_settings.list()
min_stock_map = {s["product_id"]: float(s["min_stock"]) for s in settings}
critical_products = [
sl for sl in stock_levels
if float(sl["quantity"]) < min_stock_map.get(sl["product_id"], 0)
]
# ═══════════════════════════════════════════
# 4. HR headcount
# ═══════════════════════════════════════════
employees = client.rh.employees.list(filters={"status": "active"})
departments = client.rh.departments.list()
dept_names = {d["department_id"]: d["name"] for d in departments}
dept_counts = {}
for emp in employees:
dept = dept_names.get(emp.get("department_id"), "N/A")
dept_counts[dept] = dept_counts.get(dept, 0) + 1
# ═══════════════════════════════════════════
# 5. CSV report export
# ═══════════════════════════════════════════
with open("monthly_report.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Metric", "Value"])
writer.writerow(["Revenue incl. tax", f"{total_revenue:,.2f} EUR"])
writer.writerow(["Unpaid", f"{total_unpaid:,.2f} EUR"])
writer.writerow(["Hot leads", hot_leads_count])
writer.writerow(["CRM pipeline", f"{pipeline_value:,.2f} EUR"])
writer.writerow(["Critical products", len(critical_products)])
writer.writerow(["Active employees", len(employees)])
writer.writerow(["---", "---"])
for dept, count in sorted(dept_counts.items()):
writer.writerow([f" {dept}", count])
print("Report exported: monthly_report.csv")All operations available on each resource.
# List with filters
invoices = client.sales.invoices.list(
filters={"status": "paid"},
limit=50,
offset=0
)
# Get a single item
invoice = client.sales.invoices.get("uuid-facture")# Create a record
customer = client.catalog.customers.create({
"name": "Acme Corp",
"contact_email": "contact@acme.tn",
"customer_type": "B2B",
"billing_country": "TN"
})# Update a record
client.catalog.customers.update(
"uuid-client",
{"priority": "high", "lifecycle_stage": "loyal"}
)# Bulk import (max 500)
products = [
{"name": "Widget A", "price": 29.990, "currency": "TND"},
{"name": "Widget B", "price": 49.990, "currency": "TND"},
# ... up to 500 rows
]
result = client.catalog.products.bulk_create(products)
print(f"Created: {result['created']}")# Delete a record
client.catalog.customers.delete("uuid-client")
# Verify deletion
try:
client.catalog.customers.get("uuid-client")
except LynaraError as e:
if e.status_code == 404:
print("Deleted successfully")# Count records
total = client.crm.leads.count()
print(f"Total leads: {total}")
# Search
results = client.catalog.customers.list(
search="acme",
limit=10
)
print(f"Found: {results.total_count}")
# Pagination
page1 = client.rh.employees.list(limit=20, offset=0)
page2 = client.rh.employees.list(limit=20, offset=20)All tables, columns, and types for each module. Click a table to see details.
Endpoint format:
GET /api/sdk/v1/sales/<resource>?limit=50&offset=0Every request is authenticated and isolated by company.
Generate a key from Settings > API Keys. Prefix lnr_live_ for production, lnr_test_ for development.
Authorization: Bearer lnr_live_xxxRow Level Security (RLS) ensures each key only sees its own company's data.
Configurable per key: 30 to 1,000 requests per minute based on your needs.
# Error handling
from lynara import Lynara, LynaraError
client = Lynara(
url="https://api.lynara.ai",
api_key="lnr_live_xxx",
company_id="your-company-uuid"
)
try:
invoices = client.sales.invoices.list()
except LynaraError as e:
print(f"Error {e.status_code}: {e.message}")
# 401 = Invalid API key
# 403 = Module not allowed
# 429 = Rate limit exceededCreate your account, generate an API key, and start integrating Lynara into your workflows.