Skip to main content

A comprehensive Python client library for interacting with Basalam API services

Project description

Basalam Python SDK

Python Version PyPI Version License: MIT

A comprehensive Python SDK for interacting with Basalam API services. This SDK provides a clean, developer-friendly interface for all Basalam services with full async/sync support.

Features

  • Full Async/Sync Support: All operations support both synchronous and asynchronous patterns
  • Type Safety: Built with Pydantic for robust type checking and validation
  • Multiple Authentication Methods: Support for client credentials, authorization code flow, and personal tokens
  • Comprehensive Service Coverage: Access to all Basalam services including wallet, orders, chat, and more
  • Auto-retry Logic: Built-in retry mechanisms for better reliability
  • Detailed Error Handling: Specific error classes for different failure scenarios

Installation

pip install basalam-sdk

Quick Start

from basalam_sdk import BasalamClient, PersonalToken
import asyncio

async def main():
    # Initialize with your credentials
    auth = PersonalToken(
        token="your-access-token",
        refresh_token="your-refresh-token"
    )
    client = BasalamClient(auth=auth)
    
    # Get products
    products = await client.get_products()
    print(f"Found {len(products)} products")
    
    # Get user balance
    balance = await client.get_balance(user_id=123)
    print(f"Balance: {balance}")

# Run async
asyncio.run(main())

Authentication

The SDK supports three authentication methods:

Personal Token

from basalam_sdk import PersonalToken

auth = PersonalToken(
    token="your_access_token",
    refresh_token="your_refresh_token"
)

Client Credentials (Server-to-Server)

from basalam_sdk import ClientCredentials, Scope

auth = ClientCredentials(
    client_id="your-client-id",
    client_secret="your-client-secret",
    scopes=[Scope.CUSTOMER_CHAT_READ]
)

Authorization Code (OAuth2 Flow)

from basalam_sdk import AuthorizationCode, Scope

auth = AuthorizationCode(
    client_id="your-client-id",
    client_secret="your-client-secret",
    redirect_uri="https://your-app.com/callback",
    scopes=[Scope.CUSTOMER_ORDER_READ]
)

# Get authorization URL
auth_url = auth.get_authorization_url()
# After user authorization, exchange code for tokens
token_info = await auth.get_token(code="received_code")

Available Services

Core Service

Manage vendors, products, shipping methods, and user information.

# Create a vendor
vendor = await client.create_vendor(
    user_id=123,
    request=CreateVendorSchema(
        title="My Store",
        summary="store123"
    )
)

# Create a product with images
product = await client.create_product(
    vendor_id=456,
    request=ProductRequestSchema(
        name="Sample Product",
        price=100000
    ),
    photo_files=[("photo1.jpg", photo_bytes)]
)

Wallet Service

Handle user balances, transactions, and refunds.

# Get balance
balance = await client.get_balance(user_id=123)

# Create expense
expense = await client.create_expense(
    user_id=123,
    request=SpendCreditRequest(
        amount=10000,
        reason_id=1
    )
)

Order Service

Manage shopping baskets and payment processing.

# Get active baskets
baskets = await client.get_baskets(refresh=True)

# Create payment
payment = await client.create_invoice_payment(
    invoice_id=789,
    request=CreatePaymentRequestModel(
        payment_method="credit_card"
    )
)

Chat Service

Handle messaging and conversations.

# Send message
message = await client.create_message(
    request=MessageRequest(
        chat_id=123,
        content="Hello!"
    )
)

# Get messages
messages = await client.get_messages(chat_id=123)

Search Service

Search products with advanced filtering.

# Search products
results = await client.search_products(
    request=ProductSearchModel(
        query="laptop",
        min_price=100000,
        max_price=500000
    )
)

Additional Services

  • Order Processing: Track orders and parcels
  • Upload: Secure file uploads
  • Webhook: Real-time event notifications

Sync/Async Usage

All methods support both patterns:

# Async (recommended)
balance = await client.get_balance(user_id=123)

# Sync
balance = client.get_balance_sync(user_id=123)

Documentation

For detailed documentation and examples, visit:

License

MIT License - see LICENSE for details.

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

basalam_sdk-1.0.1.tar.gz (204.0 kB view details)

Uploaded Source

Built Distribution

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

basalam_sdk-1.0.1-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file basalam_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: basalam_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 204.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for basalam_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4c206e6c2db7c0f51b9fbc6e23c064a560f6097c3e300ac4ccef4392e627cac3
MD5 d709357ca443b29396e89605c4e896e1
BLAKE2b-256 3a4b148e9d20930b91f36e7ac5f52edcac08c38de0b6e0484c755e41372db021

See more details on using hashes here.

File details

Details for the file basalam_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: basalam_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 53.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for basalam_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4874dcb993127b4c02dab927cf18c76a64980f7c3c9eabc318564e3b7615b4cc
MD5 93f148d2446256341a9b0e0f62f007be
BLAKE2b-256 1c3dfac579760c0c6a107276f87c0ae68a56b3216370ba8a027245eeed880003

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