Python SDK
Every method as a plain function taking keyword arguments, returning dicts. No dependencies.
Install
pip install lumoraPython 3.9 or later. Standard library only.
Make a call
Create a client with an access token: an API key (hg_…) from your own business, or an app's OAuth access token (lmo_at_…). Keep it on your server, never in a browser bundle or mobile app.
import os
from lumora import Lumora
lumora = Lumora(access_token=os.environ["LUMORA_ACCESS_TOKEN"])
page = lumora.orders.list_orders(page_size=50)
for order in page.get("orders", []):
print(order["number"], order["totals"]["total"]) # TZS centsReads that fail on a network error, a rate limit or a server error are retried twice, waiting as long as the API asks; writes are never retried for you, since the API can't tell a repeat from a second request. Pass a base URL to the client to point it somewhere else, such as a local API.
Connect a business with OAuth
When other businesses use your app, they connect it through Lumora's consent screen and you get tokens for their business. The OAuth guide explains each step.
from lumora import OAuth, create_pkce, create_state
oauth = OAuth(client_id=os.environ["LUMORA_CLIENT_ID"], client_secret=os.environ["LUMORA_CLIENT_SECRET"])
# 1. Send the business owner to Lumora to approve your app.
verifier, challenge = create_pkce()
state = create_state()
url = oauth.authorization_url(
"https://yourapp.co.tz/lumora/callback",
["orders.read", "catalog.write"],
state,
code_challenge=challenge,
)
# 2. On the callback, swap the code for tokens.
tokens = oauth.exchange_code(code, "https://yourapp.co.tz/lumora/callback", code_verifier=verifier)
# 3. Before tokens["expires_at"], refresh. Refresh tokens are single use.
tokens = oauth.refresh(tokens["refresh_token"])Check webhook signatures
Every delivery is signed with your endpoint's secret. Check it against the raw body before you trust the event; the helper also rejects deliveries older than five minutes. See Webhooks.
from flask import Flask, request
from lumora import verify_webhook, WebhookSignatureError, SIGNATURE_HEADER
app = Flask(__name__)
@app.post("/lumora/webhooks")
def lumora_webhook():
try:
event = verify_webhook(os.environ["LUMORA_WEBHOOK_SECRET"], request.headers.get(SIGNATURE_HEADER), request.get_data())
except WebhookSignatureError:
return "bad signature", 400
if event["type"] == "order.updated":
order = event["data"] # the whole order after the change
return "", 204Errors
Failed calls raise one error type with the API's error code, the HTTP status and, when you hit a rate limit, how long to wait. See Errors and rate limits for the codes.
from lumora import LumoraError
try:
lumora.customers.list_customers()
except LumoraError as err:
print(err.code) # "permission_denied", "resource_exhausted", ...
print(err.status) # the HTTP status
print(err.retry_after) # seconds, when rate limitedServices
Every service in the API reference is a property of the client:
| Property | Service | Methods |
|---|---|---|
lumora.orders | Orders | 11 |
lumora.catalog | Catalog | 5 |
lumora.customers | Customers | 6 |
lumora.inventory | Inventory | 82 |
lumora.invoices | Invoices and estimates | 13 |
lumora.storefront | Online store | 7 |
lumora.loco_pesa | Loco Pesa | 9 |
lumora.selcom | Selcom | 11 |
lumora.rooms | Rooms | 24 |
lumora.dining | Dining | 1 |
lumora.appointments | Appointments | 9 |
lumora.jobs | Jobs | 8 |
lumora.team | Team | 50 |
lumora.payroll | Payroll | 38 |
lumora.ledger | Ledger and cash accounts | 53 |
lumora.expenses | Expenses | 13 |
lumora.accounting | Accounting | 7 |
lumora.forecast | Forecast | 8 |
lumora.search | Search | 1 |
lumora.autopilot | Autopilot | 7 |
lumora.audit | Audit log | 2 |
lumora.locations | Locations and devices | 3 |
lumora.sync | Sync and change feed | 2 |
Source and versions
The SDK lives in sdks/python in the Lumora repository. Its service layer is regenerated whenever the API changes, and versions follow semantic versioning: a new method is a minor release, and nothing is removed without a major one.