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 Distribution

sap_rfc_connector-0.3.7.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file sap_rfc_connector-0.3.7.tar.gz.

File metadata

  • Download URL: sap_rfc_connector-0.3.7.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sap_rfc_connector-0.3.7.tar.gz
Algorithm Hash digest
SHA256 dc4f300d4088d6262599f6b5ac49057a0e810e2ba82c22d0d2feaddd01d058f8
MD5 eab9e5759127fa3bdfadcccb843c51f6
BLAKE2b-256 09a1097d20cabd63f1fbad06694fe9c99efe4122c64f514046b6d5492109a010

See more details on using hashes here.

Provenance

The following attestation bundles were made for sap_rfc_connector-0.3.7.tar.gz:

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.7-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sap_rfc_connector-0.3.7-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3ab359fa466503988f180832d52c9b5ca306e6e33dbc219300e26eba4e1577d2
MD5 0ad50df0febc71d7970d0fbd3fead626
BLAKE2b-256 69b7557e6ae4238e7055a95126f28325e64cf5accb7d045108607196a6acabed

See more details on using hashes here.

Provenance

The following attestation bundles were made for sap_rfc_connector-0.3.7-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.

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