Skip to main content

Official Python SDK for the Dark Obsidian Business Management API

Project description

dark-obsidian

Official Python SDK for the Dark Obsidian Business Management API.

pip install dark-obsidian

Quick start

from dark_obsidian import DarkObsidian

client = DarkObsidian(api_key="do_live_...")

The killer endpoint — one call connects your storefront to your entire business

from dark_obsidian import DarkObsidian
from dark_obsidian.models.orders import CreateOrderParams, CreateOrderItemParams, InlineCustomer

client = DarkObsidian(api_key="do_live_...")

order = client.orders.create(CreateOrderParams(
    items=[
        CreateOrderItemParams(product_id="prod_id_here", quantity=2),
    ],
    customer=InlineCustomer(
        name="Ahmed Khan",
        email="ahmed@example.com",
        phone="+923001234567",
    ),
    payment_method="card",
    send_invoice=True,
))

print(f"Order:   {order.order_number}")
print(f"Invoice: {order.invoice_number}")
print(f"Loyalty: {order.loyalty_points_earned} pts earned")

Resources

from dark_obsidian.models.products import ListProductsParams, CreateProductParams

# Products
products = client.products.list(ListProductsParams(in_stock=True))
product  = client.products.get("id")
created  = client.products.create(CreateProductParams(name="Panadol 500mg", price=45.0))
client.products.update("id", UpdateProductParams(price=48.0))
client.products.delete("id")

# Customers
from dark_obsidian.models.customers import CreateCustomerParams, ListCustomersParams
customers = client.customers.list(ListCustomersParams(search="Ahmed"))
customer  = client.customers.create(CreateCustomerParams(name="Fatima Malik", phone="+923331234567"))

# Inventory
from dark_obsidian.models.inventory import AdjustInventoryParams, TransferInventoryParams
client.inventory.adjust(AdjustInventoryParams(
    product_id="id", quantity=200, reason="Received from Al-Habib Distributors"
))
client.inventory.transfer(TransferInventoryParams(
    product_id="id",
    from_warehouse_id="wh-main",
    to_warehouse_id="wh-branch",
    quantity=50,
))

# Analytics
dash = client.analytics.dashboard(days=30)
top  = client.analytics.top_products(days=30, limit=10)

# AI
from dark_obsidian.models.ai import AnalyzeParams
response = client.ai.analyze(AnalyzeParams(question="What should I reorder this week?"))
print(response.answer)

Async usage

import asyncio
from dark_obsidian import AsyncDarkObsidian
from dark_obsidian.models.products import ListProductsParams

async def main():
    async with AsyncDarkObsidian(api_key="do_live_...") as client:
        products = await client.products.list(ListProductsParams(in_stock=True))
        print(f"Found {len(products)} products in stock")

asyncio.run(main())

Error handling

from dark_obsidian import DarkObsidian, DarkObsidianError
from dark_obsidian.models.errors import ErrorCode

try:
    order = client.orders.create(...)
except DarkObsidianError as err:
    print(f"[{err.code}] {err.message}")
    print(f"Request ID: {err.request_id}")   # for support

    if err.code == ErrorCode.INSUFFICIENT_STOCK:
        print("Some items are out of stock")
    elif err.code == ErrorCode.VALIDATION_ERROR and err.fields:
        for f in err.fields:
            print(f"  {f.field}: {f.message}")

Webhooks

from dark_obsidian import verify_webhook_signature
import os

# Flask example:
from flask import Flask, request, abort
import json

app = Flask(__name__)
WEBHOOK_SECRET = os.environ["DARK_OBSIDIAN_WEBHOOK_SECRET"]

@app.route("/webhooks", methods=["POST"])
def handle_webhook():
    raw_body  = request.get_data(as_text=True)
    signature = request.headers.get("X-Dark-Obsidian-Signature", "")

    if not verify_webhook_signature(WEBHOOK_SECRET, raw_body, signature):
        abort(401)

    event = json.loads(raw_body)
    print(f"Received: {event['event']}")
    return "", 200

Supported events: sale.completed, sale.voided, po.received, po.returned, inventory.low_stock, inventory.out_of_stock, invoice.payment_recorded, expense.approved, payroll.processed, leave.approved, leave.rejected, announcement.published, customer.group_upgraded

Context manager (auto-close)

with DarkObsidian(api_key="do_live_...") as client:
    products = client.products.list()
# httpx.Client is closed automatically

Requirements

  • Python 3.10+
  • httpx (installed automatically)

API reference

https://darkobsedian.sameergul.com/docs

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

dark_obsidian-1.0.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

dark_obsidian-1.0.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file dark_obsidian-1.0.0.tar.gz.

File metadata

  • Download URL: dark_obsidian-1.0.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for dark_obsidian-1.0.0.tar.gz
Algorithm Hash digest
SHA256 37ca972299e2ed296ead4742e18a48faa0693ac33f93cfd7bdb4ab7429cf8b1e
MD5 6f4308f085a03f52443bd3cf29f24618
BLAKE2b-256 929bbc41792a2b08ef24051078750c7bd785fb8516f69b32e96fc3a097ca782b

See more details on using hashes here.

File details

Details for the file dark_obsidian-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dark_obsidian-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for dark_obsidian-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b208dfa2bb8b7f68d2f2d080020f0430264a8e43b5ea2b17e00c75aa39e7e648
MD5 5a59a3d03d999dad1139c7e5c69e3e44
BLAKE2b-256 dbdb35dfd9132a5b4ace056b7e76303aac6f1bde0a34a98172e878168c1459a3

See more details on using hashes here.

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