Skip to main content

saprfclib - Pure Python SAP RFC Protocol Implementation

CI PyPI Python License: MPL 2.0 OpenSSF Best Practices

saprfclib is a pure-Python reimplementation of the SAP RFC wire protocol - zero native/C dependencies. Call any SAP function module from Python with just a pip install. Supports direct TCP, SAProuter, message server (load-balanced), SNC (X.509 and Kerberos/Active Directory SSO, built in — no SAP library needed), and WebSocket RFC (SAP BTP/cloud) connections. Requires Python 3.12 or later.

No SAP NetWeaver RFC SDK. No C compiler. No LD_LIBRARY_PATH. No container image built around a proprietary .so.

Installation

pip install saprfclib

Pulls five pure-Python dependencies: wsproto and h11 (WebSocket RFC), and asn1crypto, ecdsa and tlslite-ng (built-in SNC).

Quick Start

import saprfclib

conn = saprfclib.connect(
    ashost="your-sap-host",   # Application server hostname or IP
    sysnr=0,                  # System number (port = 3300 + sysnr)
    client="100",             # SAP client (Mandant)
    user="RFC_USER",          # SAP logon user
    passwd="secret",          # Password (never logged by saprfclib)
)

result = conn.call("STFC_CONNECTION", REQUTEXT="Hello from saprfclib!")
print(result["ECHOTEXT"])    # "Hello from saprfclib!"
print(result["RESPTEXT"])    # SAP server response text

conn.close()

conn.call() fetches function module metadata from DDIC on the first call and caches it in-process - no configuration needed.

Connection Options

Mode Key Parameters
Direct TCP ashost, sysnr
SAProuter ashost, sysnr, saprouter="/H/router/S/3299/H/target"
Message server mshost, sysid, group
SNC (X.509, built in) snc_partnername, snc_pse, snc_pse_pin (or snc_lib for a native GSS library)
SNC (Kerberos SSO, built in) snc_partnername="p:CN=<name>@<REALM>", snc_kerberos=True (Windows logon session or ticket cache) or saprfclib.krb5.KerberosLogin(...), snc_sso=True
WebSocket RFC wshost, wsport, ws_path
SOCKS5 proxy (SAP BTP) proxy_type="socks5", proxy_host, proxy_port (+ proxy_jwt / OAuth triple)

Reach an on-premise system through the SAP BTP Connectivity Proxy / Cloud Connector (e.g. from a Kyma workload) with no NW RFC SDK or Transparent Proxy:

# trusted mode (no proxy authentication)
conn = saprfclib.connect(
    ashost="s4-2025-raw", sysnr="00", client="001", user="Developer", passwd="...",
    proxy_type="socks5",
    proxy_host="connectivity-proxy.kyma-system.svc.cluster.local",
    proxy_port=20004,
    gwhost="vhcala4hci",  # SAP system's internal host (ashost is the virtual tunnel host)
)

# untrusted mode — SAP JWT (method 0x80), token fetched via client_credentials
conn = saprfclib.connect(
    ashost="s4-2025", sysnr="00", client="001", user="Developer", passwd="...",
    proxy_type="socks5", proxy_host="...", proxy_port=20004,
    proxy_client_id="...", proxy_client_secret="...",
    proxy_token_url="https://<subaccount>.authentication.<region>.hana.ondemand.com/oauth/token",
    proxy_scc_location_id="MyLocation",  # optional Cloud Connector location
)

# or let saprfclib read the bound Connectivity service (VCAP_SERVICES / SERVICE_BINDING_ROOT)
cfg = saprfclib.connectivity_proxy_kwargs()           # add with_auth=False in trusted mode
conn = saprfclib.connect(ashost="s4-2025", sysnr="00", client="001",
                         user="Developer", passwd="...", **cfg)

See the Connection Options guide for the full parameter reference.

Documentation

Full documentation: https://randomstr1ng.github.io/saprfclib/

  • Getting Started - install, connect, and make your first call in 10 minutes
  • Cookbook - TABLE parameters, RFC server, tRFC/qRFC, connection pool, SNC, WebSocket RFC
  • API Reference - auto-generated from typed docstrings via MkDocs + mkdocstrings
  • Protocol Docs - NI/CPIC framing, ABAP type serialization, RFC handshake, SNC, tRFC/bgRFC wire specs

Example Scripts

The examples/ directory contains runnable scripts for common patterns:

Script Pattern
examples/01_connect_and_call.py Basic connect → call → close
examples/02_table_params.py RFC_READ_TABLE with TABLE parameters
examples/03_connection_pool.py Multi-threaded connection pool
examples/04_trfc_submit.py tRFC / qRFC lifecycle
examples/05_rfc_server.py RFC server with handler
examples/06_snc_connection.py SNC X.509 connection
examples/07_websocket_rfc.py WebSocket RFC to SAP BTP
examples/08_read_table.py RFC_READ_TABLE with every TABLE parameter
examples/09_bapi_user_create.py BAPI structures and return tables
examples/10_snc_kerberos_sso.py Kerberos SNC single sign-on (Active Directory)

All examples read connection parameters from SAPRFC_* environment variables.

Development

git clone https://github.com/randomstr1ng/saprfclib
cd saprfclib
pip install -e ".[dev]"
# Run offline test suite (no live SAP needed)
hatch run test -m "not integration"

# Lint and format
hatch run lint:check
hatch run lint:fmt

# Type-check
hatch run lint:type

# Build wheel + sdist
hatch build

Live integration tests require a running SAP system. Set environment variables:

export SAPRFC_ASHOST=your-sap-host
export SAPRFC_SYSNR=0
export SAPRFC_CLIENT=100
export SAPRFC_USER=RFC_USER
export SAPRFC_PASSWD=secret
pytest -m integration

See CONTRIBUTING.md for the full contributor guide, and CLAUDE.md for the protocol-fidelity rules every change must follow.

License

Licensed under the Mozilla Public License 2.0 - see LICENSE.

MPL-2.0 is deliberate: you may use saprfclib inside a closed-source, commercial product with no obligation to release your own code. If you modify saprfclib's own source files, those modified files must remain under MPL-2.0 and be made available. Improvements to the library flow back; your product stays yours.

Trademarks and Affiliation

This project is not affiliated with, endorsed by, or supported by SAP SE. SAP, ABAP, SAP NetWeaver, SAProuter, and SAP S/4HANA are trademarks or registered trademarks of SAP SE in Germany and other countries, used here for identification only. saprfclib contains no SAP code, binaries, or headers. Using it does not grant you any licence to SAP software - you remain responsible for your own SAP licensing.

See NOTICE for details.

Metadata

Release files for saprfclib 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for saprfclib 0.2.1
File Size Uploaded Provenance Actions
saprfclib-0.2.1.tar.gz 1.4 MB With provenance Details for saprfclib-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for saprfclib 0.2.1
File Interpreter ABI Platform Actions
saprfclib-0.2.1-py3-none-any.whl Python 3 none any Details for saprfclib-0.2.1-py3-none-any.whl

Total release size: 1.7 MB

Release files / saprfclib-0.2.1.tar.gz

Download URL saprfclib-0.2.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
0dad7c02bbcbfa219bbebd93c228bfa765bd6760fd81903748a515fa43bd10bd
BLAKE2b-256 checksum
How to use checksums
a58f8bd4138f0d6c1f1a28a72e5abbebdadf0bf1c4153e797de4e94ad88d8790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / saprfclib-0.2.1-py3-none-any.whl

Download URL saprfclib-0.2.1-py3-none-any.whl
Size 325.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff310366b17e594466bc85045b609fddefa3feab397b9312aba8967bcc83908b
BLAKE2b-256 checksum
How to use checksums
3ce4a1d5ad99a927423e102686dcfe79f69fe613fc49d3016d04177963ae2139
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for saprfclib 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for saprfclib-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page