Skip to main content

SAP RFC wrapper written in C++ with Python bindings

Project description

sap_rfc_connector

sap_rfc_connector is a C++17 + pybind11 wrapper around the SAP NetWeaver RFC SDK. It exposes a small Python API for opening a SAP connection, calling RFC functions, and reading metadata.

What this package provides

  • Python extension module: sap_rfc_connector
  • C++ connector class: SapRfcConnector
  • C++ function caller: sap_rfc::SapFunctionCaller
  • Python bindings for:
    • SapRfcConnector
    • SapFunctionCaller

All RFC payload values are currently exchanged as strings (dict[str, str] style), including table rows.

Requirements

  • Python >=3.7
  • C++ compiler with C++17 support
  • SAP NetWeaver RFC SDK (headers + libraries)
  • Environment variable SAPNWRFC_HOME pointing to the SDK root

Expected SDK layout:

  • ${SAPNWRFC_HOME}/include
  • ${SAPNWRFC_HOME}/lib

Build / Install

From this directory:

python -m pip install --upgrade pip setuptools wheel pybind11
python -m pip install .

For local development build:

python setup.py build_ext --inplace

Quick start (Python)

from sap_rfc_connector import SapRfcConnector, SapFunctionCaller

conn = SapRfcConnector(
    user="YOUR_USER",
    passwd="YOUR_PASSWORD",
    ashost="YOUR_ASHOST",
    sysnr="00",
)

caller = SapFunctionCaller(conn)

result = caller.call(
    "STFC_CONNECTION",
    REQUTEXT="Hello SAP",
)

print(result)

Example with table parameters:

result = caller.call(
    "BBP_RFC_READ_TABLE",
    QUERY_TABLE="KONP",
    DELIMITER="|",
    ROWCOUNT=1000,
    FIELDS=["KNUMH", "KOPOS", "KAPPL", "KSCHL", "KBETR"],
    OPTIONS=[{"TEXT": "KAPPL = 'KA'"}],
)

Python binding behavior

SapRfcConnector(**kwargs) validation

The kwargs constructor requires:

  • user
  • passwd
  • ashost
  • sysnr

If one is missing, it raises ValueError. If connection fails, it raises RuntimeError.

SapFunctionCaller.call(func, **kwargs)

Binding-side parsing rules:

  • Non-list kwargs are treated as scalar RFC params.
  • List kwargs are treated as table params.
  • Special-case FIELDS=["COL1", "COL2"] is converted to:
    • [{"FIELDNAME": "COL1"}, {"FIELDNAME": "COL2"}]
  • Table row dict values are normalized to string via Python str(...).
    • None becomes empty string.
    • bytes are decoded as Python bytes-to-str cast result.

C++ design notes

  • SapRfcConnector is intentionally non-copyable and non-movable to avoid handle ownership bugs.
  • RFC function handles are wrapped with RAII (RfcFunctionHandle).
  • Input table field write errors now fail fast with an exception (no silent partial row writes).
  • Output field extraction uses a safe fallback marker when SAP field read fails:
    • "<unreadable:RFCTYPE_...>"

Encoding behavior

utils::fromSAPUC attempts UTF conversion first. If conversion fails, it returns escaped code units (\uXXXX) instead of replacing data with spaces.

Public API summary

SapRfcConnector

  • connect(user, passwd, ashost, sysnr) -> bool
  • check_connection() -> bool
  • close_connection()
  • get_library_info() -> dict[str, int]

sap_rfc::SapFunctionCaller

  • get_function_description(function_name) -> list[dict[str, str]]
  • call(func, params, tables) -> dict[str, list[dict[str, str]]]
  • get_table_metadata(table_name) -> list[dict[str, str]]

Notes for high-volume workloads

Current API materializes output tables in memory as nested Python/C++ maps of strings. For very large result sets, plan calls in chunks at the query/source level where possible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

sap_rfc_connector-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

sap_rfc_connector-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

File details

Details for the file sap_rfc_connector-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sap_rfc_connector-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d433b9424b585017c6242d02f35cc8e2a26f0d2b9cfc0ac90111dd482af0b2b2
MD5 14e764e6f6bf091133dd83953efbdb17
BLAKE2b-256 e99a8955f65308dc63caa6db5e92bee36016c4fbd3572025ea28d97b0e674de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for sap_rfc_connector-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish_to_pypi.yml on dyvenia/sap_rfc_connector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sap_rfc_connector-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sap_rfc_connector-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 471495aec4b0f503311d4bbecf84ec1695e8737fb864ef5d82a916a387154abe
MD5 b63a46ab040112b6b1db3b8d95174fff
BLAKE2b-256 73d676e5361a3a2fa96fed43e230f80d426f2b6d675903ab976097a1841e1918

See more details on using hashes here.

Provenance

The following attestation bundles were made for sap_rfc_connector-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl:

Publisher: publish_to_pypi.yml on dyvenia/sap_rfc_connector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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