Skip to main content

A framework-agnostic Python SDK for SAP Business One Service Layer and SAP HANA. (Unofficial)

Project description

b1sl-python

Modern, async-first Python SDK for SAP Business One Service Layer.

b1sl Banner

Python Version License Pydantic v2 Built with httpx

b1sl is a high-performance SDK designed for the SAP B1 Service Layer, focusing on concurrency, type safety, and efficient session management.


Key Features

  • Async-First Architecture: Built on top of httpx for non-blocking I/O.
  • Type Safety: Full Pydantic v2 integration for all SAP entities.
  • Smart Session Management: Automatic 401 re-authentication with internal locking to prevent license exhaustion.
  • Session Hydration: Reuse existing B1SESSION IDs across serverless functions or Temporal activities.
  • Optimistic Concurrency: Automated ETag handling with smart cache invalidation on 412 conflicts.
  • Pythonic Querying: Fluent OData builder with operator overloading and type-safe fields.
  • Observability: Structured logging and event hooks for performance monitoring.
  • Safe Development: Global and per-request Dry Run mode to intercept writing requests.

Installation

# Using pip
pip install b1sl-python

# Using uv
uv add b1sl-python

Quick Start

import asyncio
from b1sl.b1sl import AsyncB1Client, B1Config

async def main():
    config = B1Config.from_env() 
    
    async with AsyncB1Client(config) as b1:
        # Full type hints for items and major entities
        item = await b1.items.get("I1000")
        
        # 1. Native Pythonic access (snake_case)
        print(f"Item: {item.item_name}")
        
        # 2. Dynamic access by SAP Alias (perfect for UDFs!)
        print(f"Stock: {item.get('QuantityOnStock')}")

if __name__ == "__main__":
    asyncio.run(main())

Pythonic Querying

Experience the best way to interact with SAP Service Layer. No more string concatenation!

from b1sl.b1sl.fields import Item
from datetime import date

# Fluent queries are type-safe, readable, and support IDE autocomplete
items = await b1.items.filter(
    (Item.quantity_on_stock > 0) & (Item.valid_from >= date(2024, 1, 1))
).select(
    Item.item_code, 
    Item.item_name
).top(5).execute()

for item in items:
    print(f"[{item.item_code}] {item.item_name}")

Advanced Usage: FastAPI Integration

b1sl is optimized for modern web frameworks. We recommend using the Lifespan pattern to share a single connection pool:

from fastapi import FastAPI
from contextlib import asynccontextmanager
from b1sl.b1sl import AsyncB1Client, B1Config

b1_client = None

@asynccontextmanager
async def lifespan(app: FastAPI):
    global b1_client
    config = B1Config.from_env()
    b1_client = AsyncB1Client(config)
    await b1_client.connect()
    yield
    await b1_client.aclose()

app = FastAPI(lifespan=lifespan)

@app.get("/items/{item_code}")
async def get_item(item_code: str):
    return await b1_client.items.get(item_code)

Architecture Overview

Feature Implementation Benefit
HTTP Engine httpx (Async/Sync) Superior performance & timeouts
Data Models Pydantic v2 Instant validation & IDE autocomplete
Auth Auto-retry 401 & Hydration Zero-downtime session management
Concurrency Shared Connection Pool Prevents SAP License Exhaustion

Why b1sl?

In production environments, SAP Business One Service Layer is sensitive to session limits and licensing costs. Traditional wrappers often create redundant connections, leading to overhead and frequent auth failures.

b1sl addresses these issues through:

  1. Session Persistence: Maintaining long-lived sessions and performing atomic re-authentication.
  2. Resource Efficiency: Validated Pydantic models reduce runtime exceptions and memory footprint.
  3. Concurrency Control: Internal locking ensures that concurrent requests wait for a single login attempt instead of triggering multiple auth calls.

SAP Compatibility

This SDK is optimized for modern Service Layer environments and defaults to v2 (OData V4).

  • Verified Baseline: Service Layer 1.27 (SAP 10.0 FP 2405).
  • Minimum for ETags: Requires Service Layer 1.21+ (March 2021).
  • Backward Compatibility: Supports v1 (OData V2) through client configuration.

For a detailed history of Service Layer features and specific version support, see the Full Compatibility Timeline.


Contributing

Contributions are welcome. Please open an issue to discuss proposed changes before submitting a pull request.


License

MIT © 2026.

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

b1sl_python-0.1.2.tar.gz (493.1 kB view details)

Uploaded Source

Built Distribution

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

b1sl_python-0.1.2-py3-none-any.whl (693.1 kB view details)

Uploaded Python 3

File details

Details for the file b1sl_python-0.1.2.tar.gz.

File metadata

  • Download URL: b1sl_python-0.1.2.tar.gz
  • Upload date:
  • Size: 493.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for b1sl_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d2cc507012961aff13f8a6b5302a0d0f79aa236d830dad3eb1b1fe4df4fb39db
MD5 b91aca0b7e61d8a8278c324264cc4e2f
BLAKE2b-256 66f4183bb9e768e1ac4fecbfbfaa2f61156dc227d01d07f78b6e410714d0d250

See more details on using hashes here.

File details

Details for the file b1sl_python-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: b1sl_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 693.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for b1sl_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d9b95aad2bd16c08f74cd6d596582aa66b14c13b0699842308c62ed2012dbf
MD5 59666e9a220c7d1756a2a43ca4019edf
BLAKE2b-256 5a2df6cde947b4394fec2ce58caa3419ea4369ec182f5a1eca72a760f6e8f449

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