Package: pyrfc
PyRFCAsynchronous, non-blockingSAP NetWeawer RFC SDKbindings for Python.FeaturesSupported platformsRequirementsSAP NW RFC SDK 7.50 Patch Level 12LinuxWindowsmacOSDockerDownload and installationGetting startedCall ABAP Function Module from PythonCall Python function from ABAPSPJ articlesHow to obtain supportContributingCode of ConductFeaturesClient and Server bindingsAutomatic conversion between Python and ABAP datatypesStateless and stateful connections (multiple function calls in the same ABAP session / same context)Sequential and parallel calls, using one or more clientsThroughput monitoringSupported platformsAllplatforms supported by SAP NWRFC SDKare supported by build from source installation (build instructions)In addition, pre-built wheels are provided for Windows, Darwin and Ubuntu Linux, attached to PyRFC GitHubreleaseDocker containers:SAP fundamental-tools/dockerLinux wheels supported by build from source installation onlyPre-builtportable Linux wheelsare not supported, neither issues related to portable Linux wheelsmust notbe distributed with embedded SAP NWRFC SDK binaries, only private use permittedRequirementsSAP NW RFC SDK 7.50 Patch Level 12seeSAP Note 3274546for a list of bug fixes and enhancements made with this patch releaseUsing the latest version is recommended as SAP NWRFC SDK is fully backwards compatible, from today S4, down to R/3 release 4.6C.Can be downloaded from SAP Software Download Center of the SAP Support Portal, like described athttps://support.sap.com/nwrfcsdk.If you are lacking the required authorization for downloading software from the SAP Service Marketplace, please follow the instructions ofSAP Note 1037575for requesting this authorization.LinuxPyRFC is using source distribution (sdist) installation on Linux systems andCythonis required on Linux system to build the PyRFC package from source. SeeInstalling CythonWindowsVisual C++ Redistributable Package for Visual Studio 2013is required for run-time, seeSAP Note 2573790 - Installation, Support and Availability of the SAP NetWeaver RFC Library 7.50Build toolchain for Python requiresMicrosoft C++ Build Tools, the latest version recommendedDue to achange introduced with Python 3.8 for Windows, PATH directories are no longer searched for DLL. The SAP NWRFC SDK lib path is no longer required on PATH, for Python >= 3.8.macOSRemote paths must be set in SAP NWRFC SDK for macOS:documentationWhen the PyRFC is started for the first time, the popups may come-up for each NWRFC SDK library, to confirm the usage. If SAP NW RFC SDK is installed in admin folder, the app shall be first time started with admin privileges, eg.sudo -EDockerDocker container examples for Linux, Intel and ARM based Darwin:SAP/fundamental-tools/docker. SAP NWRFC SDK libraries are not included.Download and installationpipinstallpyrfcOn Windows and macOS platforms pre-built binary wheel is installed, without local compilation. On Linux platform the package is locally built from source distribution.Build from source distribution can be requested also on other platforms:pipinstall--no-binarypyrfcpyrfc# orpipinstallhttps://files.pythonhosted.org/packages/.../pyrfc-3.1.0.tar.gzAlternative build from source installation:gitclonehttps://github.com/SAP/PyRFC.gitcdPyRFC# if you use toxtox-epy311# for Python 3.11# orpython-mpipinstall.# orpython-mbuild--wheel--sdist--outdirdist# orPYRFC_BUILD_CYTHON=yespython-mbuild--wheel--sdist--outdirdist
pipinstall--upgrade--no-index--find-links=distpyrfcRunpythonand typefrom pyrfc import *. If this finishes silently, without oputput, the installation was successful.Using virtual environments you can isolate Python/PyRFC projects, working without administrator privileges.See also thepyrfc documentation,
complementingSAP NWRFC SDKdocumentation, especiallySAP NWRFC SDK 7.50 Programming Guide.Getting startedNote:The package must beinstalledbefore use.Call ABAP Function Module from PythonIn order to call remote enabled ABAP function module (ABAP RFM), first a connection must be opened.frompyrfcimportConnectionconn=Connection(ashost='10.0.0.1',sysnr='00',client='100',user='me',passwd='secret')Connection parameters are documented insapnwrfc.inifile, located in theSAP NWRFC SDKdemofolder. Check also section4.1.2 Using sapnwrfc.iniofSAP NWRFC SDK 7.50 Programming Guide.Using an open connection, remote function modules (RFM) can be invoked. More info inpyrfc documentation.# ABAP variables are mapped to Python variablesresult=conn.call('STFC_CONNECTION',REQUTEXT=u'Hello SAP!')print(result){u'ECHOTEXT':u'Hello SAP!',u'RESPTEXT':u'SAP R/3 Rel. 702   Sysid: ABC   Date: 20121001   Time: 134524   Logon_Data: 100/ME/E'}# ABAP structures are mapped to Python dictionariesIMPORTSTRUCT={"RFCFLOAT":1.23456789,"RFCCHAR1":"A"}# ABAP tables are mapped to Python lists, of dictionaries representing ABAP tables' rowsIMPORTTABLE=[]result=conn.call("STFC_STRUCTURE",IMPORTSTRUCT=IMPORTSTRUCT,RFCTABLE=IMPORTTABLE)printresult["ECHOSTRUCT"]{"RFCFLOAT":1.23456789,"RFCCHAR1":"A"...}printresult["RFCTABLE"][{"RFCFLOAT":1.23456789,"RFCCHAR1":"A"...}]Finally, the connection is closed automatically when the instance is deleted by the garbage collector. As this may take some time, we may either call the close() method explicitly or use the connection as a context manager:withConnection(user='me',...)asconn:conn.call(...)# connection automatically closed hereAlternatively, connection parameters can be provided as a dictionary:defget_connection(conn_params):"""Get connection"""print'Connecting ...',conn_params['ashost']returnConnection(**conn_param)frompyrfcimportConnectionabap_system={'user':'me','passwd':'secret','ashost':'10.0.0.1','saprouter':'/H/111.22.33.44/S/3299/W/e5ngxs/H/555.66.777.888/H/','sysnr':'00','client':'100','trace':'3',#optional, in case you want to trace'lang':'EN'}conn=get_connection(**abap_system)Connecting...10.0.0.1conn.aliveTrueSee also pyrfc documentation forClient ScenarioCall Python function from ABAP# create server for ABAP system ABCserver=Server({"dest":"gateway"},{"dest":"MME"},{"port":8081,"server_log":False})# expose python function my_stfc_connection as ABAP function STFC_CONNECTION, to be called from ABAP systemserver.add_function("STFC_CONNECTION",my_stfc_connection)# start serverserver.start()# get server attributesprint("Server attributes",server.get_server_attributes())# stop serverinput("Press Enter to stop servers...")server.stop()print("Server stoped")See also pyrfc documentation forServer Scenarioand server examplesource code.SPJ articlesHighly recommended reading about RFC communication and SAP NW RFC Library, published in the SAP Professional Journal (SPJ)Part I RFC Client ProgrammingPart II RFC Server ProgrammingPart III Advanced TopicsHow to obtain supportIf you encounter an issue or have a feature request, you can create aticket.Check out theSAP Community(search for "pyrfc") and stackoverflow (use the tagpyrfc), to discuss code-related problems and questions.ContributingWe appreciate contributions from the community toPyRFC!
SeeCONTRIBUTING.mdfor more details on our philosophy around extending this module.Code of ConductSeeCode of Conduct