Official Python SDK for the Daily Life Pharmacy enterprise platform
Project description
dlp-sdk - Daily Life Pharmacy Python SDK
Official Python SDK for the Daily Life Pharmacy enterprise platform. It wraps the REST API in a typed, session-aware client for customer, admin, and mobile workflows.
Installation
Install from PyPI once the package is published:
pip install dlp-sdk
Install from a local checkout:
pip install .
Install with development dependencies:
pip install -e .[dev]
Requirements:
- Python 3.10+
requests>=2.31
Quick Start
from dlp_sdk import DLPClient
sdk = DLPClient("https://pharmacy.example.com")
print(sdk.health())
Authentication
Admin Login
sdk.auth.admin_login("admin", "yourpassword")
# With 2FA (TOTP)
sdk.auth.admin_login("admin", "yourpassword", totp_code="123456")
# Fetch authenticator QR URI (must be logged in)
uri = sdk.auth.totp_qr_uri()
print(uri)
sdk.auth.admin_logout()
Customer OTP
result = sdk.auth.otp_request("+8801712345678")
print(result.otp) # dev/demo only
verified = sdk.auth.otp_verify("+8801712345678", "123456")
if verified.valid:
print(f"Welcome, {verified.customer_name}!")
Catalog
products = sdk.catalog.list_products()
pain_killers = sdk.catalog.list_products(
category="painkiller",
sort="price_asc",
limit=20,
)
results = sdk.catalog.list_products(search="paracetamol")
featured = sdk.catalog.list_products(featured=True)
product = sdk.catalog.get_product(1)
product = sdk.catalog.get_product_by_slug("paracetamol-500mg")
print(product.name, product.price, product.stock)
related = sdk.catalog.related_products(product_id=1, limit=4)
Cart
The cart is session-based. The SDK preserves the session cookie automatically.
sdk.cart.add(product_id=1, quantity=2)
sdk.cart.add(product_id=5, quantity=1)
cart = sdk.cart.get()
print(f"Items: {len(cart.items)}")
print(f"Subtotal: {cart.subtotal}")
print(f"Delivery: {cart.delivery}")
print(f"Grand total: {cart.grand_total}")
for item in cart.items:
print(f"{item.name} x {item.qty} = {item.subtotal}")
result = sdk.cart.apply_promo("SAVE10")
if result["valid"]:
print(f"Saved {result['discount_amount']}")
sdk.cart.remove_promo()
sdk.cart.update(product_id=1, quantity=3)
sdk.cart.remove(product_id=5)
sdk.cart.clear()
Orders
sdk.cart.add(product_id=1, quantity=2)
sdk.cart.apply_promo("SAVE10")
order = sdk.orders.create(
name="Fatima Khanam",
phone="+8801987654321",
address="House 7, Road 3, Mirpur-1",
city="Dhaka",
payment_method="bKash",
email="fatima@example.com",
note="Please ring the bell twice.",
)
print(order.order_code)
print(order.status)
print(order.eta)
print(order.grand_total)
for item in order.items:
print(item.product_name, item.quantity)
order = sdk.orders.get("DLP12345678")
Order statuses: Confirmed -> Processing -> Shipped -> Delivered
Admin
sdk.auth.admin_login("admin", "secret")
stats = sdk.admin.stats()
print(stats.order_count, stats.pending_orders)
print(stats.revenue)
print(stats.unread_messages)
reports = sdk.admin.reports()
print(reports.sales.average_order)
print(reports.operations.active_promos)
for product in reports.top_products[:5]:
print(product.name, product.units, product.sales)
integrations = sdk.admin.integrations()
print(integrations.whatsapp_logs, integrations.label_documents)
Invoice PDF
pdf_bytes = sdk.admin.download_invoice(order_id=42)
sdk.admin.download_invoice(order_id=42, dest_path="/tmp/invoice_DLP12345678.pdf")
WhatsApp Link
link = sdk.admin.whatsapp_link(order_id=42)
print(link)
Barcodes and QR Codes
sdk.admin.download_barcode(product_id=7, dest_path="/tmp/barcode_7.pdf")
sdk.admin.download_qr(product_id=7, dest_path="/tmp/qr_7.pdf")
Shipping and Item Labels
sdk.admin.download_shipping_label(order_id=42, dest_path="/tmp/ship_label.pdf")
sdk.admin.download_item_labels(order_id=42, dest_path="/tmp/item_labels.pdf")
Mobile and Content
home = sdk.mobile.home()
for banner in home.banners:
print(banner.title, banner.image_url)
for post in home.blog_posts:
print(post.title, post.slug)
sdk.mobile.wishlist_add(product_id=3)
items = sdk.mobile.wishlist()
sdk.mobile.newsletter_subscribe("customer@example.com")
Error Handling
from dlp_sdk import (
DLPClient,
AuthenticationError,
AuthorizationError,
NotFoundError,
ValidationError,
RateLimitError,
ServerError,
NetworkError,
)
sdk = DLPClient("https://pharmacy.example.com")
try:
sdk.auth.admin_login("admin", "wrongpass")
except AuthenticationError as exc:
print(f"Login failed [{exc.status_code}]: {exc}")
try:
sdk.catalog.get_product(99999)
except NotFoundError:
print("Product not found")
try:
sdk.cart.apply_promo("INVALID")
except ValidationError as exc:
print(f"Promo error: {exc}")
try:
sdk.health()
except NetworkError:
print("Server unreachable")
| Exception | When raised |
|---|---|
AuthenticationError |
401 bad credentials or expired session |
AuthorizationError |
403 insufficient role |
NotFoundError |
404 resource does not exist |
ValidationError |
400 or 422 invalid request data |
RateLimitError |
429 too many requests |
ServerError |
5xx server-side error |
NetworkError |
timeout, connection refused, or DNS failure |
Configuration
sdk = DLPClient(
"https://pharmacy.example.com",
timeout=30,
verify_ssl=True,
debug=True,
)
Running Tests
Install the package and development dependencies first:
pip install -e .[dev]
pytest tests/test_sdk.py -v
If you prefer non-editable installs:
pip install .[dev]
pytest tests/test_sdk.py -v
Resource Overview
| Resource | Attribute | Key Methods |
|---|---|---|
| Authentication | sdk.auth |
admin_login, admin_logout, otp_request, otp_verify, totp_qr_uri |
| Catalog | sdk.catalog |
list_products, get_product, get_product_by_slug, related_products |
| Cart | sdk.cart |
get, add, update, remove, apply_promo, remove_promo, clear |
| Orders | sdk.orders |
create, get, validate_promo |
| Admin | sdk.admin |
stats, reports, integrations, download_invoice, whatsapp_link, download_barcode, download_qr, download_shipping_label, download_item_labels |
| Mobile/Content | sdk.mobile |
home, wishlist, wishlist_add, newsletter_subscribe |
License
MIT Copyright Daily Life Pharmacy Engineering
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dlp_sdk-1.0.0.tar.gz.
File metadata
- Download URL: dlp_sdk-1.0.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cc9d8c0fe41f8cae6a7f71277524073338dc8c76d2156560e55ab8c791b1cac
|
|
| MD5 |
6e64cdaed8d70fa5bf023f648389cffd
|
|
| BLAKE2b-256 |
457f4b044ac9902cb9e5012da42723dfd8045000039871d9b78f1fdaf51f4489
|
File details
Details for the file dlp_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dlp_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b8aa8763c3ba890ebe8c7b7c96fa560d45c48aa432bdd45fac04dcbb260bd76
|
|
| MD5 |
4dcd7944e2f6d0830c417cd986aae705
|
|
| BLAKE2b-256 |
17ab55fd0013a31aecdadf0be458a97ae199fd5870edb6fc828463b6a460a3f0
|