Skip to main content

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

Project description

b1sl

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.
  • Observability: Structured logging and event hooks for performance monitoring.

Installation

# Using pip
pip install b1sl

# Using uv
uv add b1sl

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("C1000")
        print(f"Item: {item.ItemName}")

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

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.0.tar.gz (479.0 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.0-py3-none-any.whl (681.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: b1sl_python-0.1.0.tar.gz
  • Upload date:
  • Size: 479.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for b1sl_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7235ec7776652873fe20a13fd27ae8bbd9530afe8b52d6da64d04e74ded97d17
MD5 47d09b4c276b7b1968cff677533be3b3
BLAKE2b-256 4b768796bc078a7a97f5355b5df58c2bd5d457f299909ca961e151c1226eec8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: b1sl_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 681.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for b1sl_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7bd620872c8cfed451ad0044161b6d42e27ee9b44a487fe2fdae26431c11f2a
MD5 fa445bc3d336e191907f7fb363c930b1
BLAKE2b-256 e1be2bcf544ed68905826d4f351ab4c0c5a5e04d148964d859e4eec809fed3f2

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