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

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("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.1.tar.gz (480.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.1-py3-none-any.whl (681.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: b1sl_python-0.1.1.tar.gz
  • Upload date:
  • Size: 480.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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.1.tar.gz
Algorithm Hash digest
SHA256 b4c53cbf7f9332a5672e9c05ada1b24b03b0596c52d8bc22c8fbe494374b301b
MD5 1a97c17f99eea3c4840e41faa46cdf42
BLAKE2b-256 51fcf5967d5aed68430e3a62c7f751e7aed94f6080622fc178c6540482c1305d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: b1sl_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 681.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f7faa0d56f779c0ea9990917d8d00038394f5db701e0a0cb968e89288a31ff7
MD5 3eec4bee2c7387e7e572644106de094d
BLAKE2b-256 9da8dfb5aa10a10cea45806e11453670600b521c06cf933001151628d98cffef

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