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 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
httpxfor 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
B1SESSIONIDs 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:
- Session Persistence: Maintaining long-lived sessions and performing atomic re-authentication.
- Resource Efficiency: Validated Pydantic models reduce runtime exceptions and memory footprint.
- 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
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 b1sl_python-0.2.0.tar.gz.
File metadata
- Download URL: b1sl_python-0.2.0.tar.gz
- Upload date:
- Size: 497.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46a9ceae162d53b0af72755a6d910c057332e2568c6a3cd2b82fab221c5b007e
|
|
| MD5 |
8bd4af9af5a93c289d65e75b1aa69ebc
|
|
| BLAKE2b-256 |
21670efee0f650c5020faffc1dfd6bc046469eed309648484ea7332416633186
|
File details
Details for the file b1sl_python-0.2.0-py3-none-any.whl.
File metadata
- Download URL: b1sl_python-0.2.0-py3-none-any.whl
- Upload date:
- Size: 695.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ceef4af426af7afb0acf9a5e222c4e02a746a6dee14ea8353ef265beca7f1b8
|
|
| MD5 |
d9211ea0bb339723146207ff94e08e3f
|
|
| BLAKE2b-256 |
61b6ad7d236b6974f76b72951341d194927b01cf6f206fec89711577f96bd573
|