Additional Blogs by Members
Showing results for 
Search instead for 
Did you mean: 

Python is an easy to learn programming language. As the documentation on the official Python page says, "Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages. Python is powerful... and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open".

The PyRFC module is the newest way to get externally running Python code integrated with SAP.  Srdjan Boskovic explains nicely why you would want a Python/ABAP stack. As he says, "Our language of choice for the web development is Python and a frequent question we hear is why we are using Python and not Java, the de-facto standard for the enterprise."

Setup and installation of PyRFC isn't too difficult on GNU/Linux and OS X. On Windows, it can be a little painful for Python noobies as the C-extension needs to be compiled, and by default Windows doesn't ship with a compiler. These instructions are geared more towards beginners and get you started in the barest possible time without having to compile, as I've pre-compiled the module for you. I've tested this process on Windows 7 and 8.

Quick setup process:

  • Install Python 2 32-bit version. Get Python from and choose to download for Windows. Then select "Latest Python 2 Release", which at the time of writing this was 2.7.8. I choose the "Windows x86 MSI Installer" file. When I install, I prefer to install "just for me", and I choose the option to add python.exe to Path

  • You'll need SAP's C-connector, NWRFC. And in order to get that you'll also need an "S-number" (SAP logon) that allows you to download software from the SAP support website. Here is a PDF telling you how to get the files you need from the SAP support site.

  • Extract the C-connector. Here's how: open a cmd shell (or PowerShell) and do: 

SAPCAR_315-20010451.EXE -xvf NWRFC_24-20004566

(Note that I used the Windows/IA32 versions of these files, and that the version numbers of the files that you download might not be the same, adjust accordingly!)

  • "Install" the C-connector. Put the "nwrfcsdk" folder that the above step created where you want it installed. For this exercise, I moved it to be under C:\Python27\

It will be necessary to adjust your environmental variables for the install location. Open environmental variables editor, which can be opened as follows: open Control Panel, go to System and Security, then  "System", "Advanced System Settings", then click the "Environmental Variables" button. Edit the "Path" environmental variable. This should already have C:\Python\27\ added to it, but we need to also add:


to the end of the list. Obviously put another path in if your path isn't C:\Python27\nwrfcsdk\lib

If you forget to set the Path, then your Python code won't be able to use the C-connector and you'll get an error message: "ImportError: DLL load failed"

  • We need setuptools so that we have easy_install. Download From a cmd prompt install it like so:


  • And now for our Trademarked "Secret Sauce" which is why you're reading this article! Use easy_install to install this prebuilt binary Python .egg file for PyRFC (md5 846946fe9c8596d186dbadb9258eca66).

From a cmd prompt install as follows:

C:\Python27\Scripts\easy_install-2.7.exe pyrfc-1.9.4-py2.7-win32.egg
  • Finally, we can test it:

Create a config file, sapnwrfc.cfg and insert content like this, obviously set the correct ashost (sap system), client, sysnr, user, passwd:

# sap system ip
ashost = xxxxxxx
# sap client id
client = 001
# sap router string, optional, format like /H/x.x.x.x/...
saprouter =
# sap system number
sysnr = 00
# sap username
# sap password
passwd = xxxxxxx2
# gateway host name
gwhost =
# gateway server name
ghserv =
# name under which the python connector will register itself
program_id = PYRFC_SERVER1
# sap router string, optional
saprouter =

Create a test program file "" and paste the following into it:

#!/usr/bin/env python
from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
from ConfigParser import ConfigParser
from pprint import PrettyPrinter

def main():

        config = ConfigParser()'sapnwrfc.cfg')
        params_connection = config._sections['connection']
        conn = Connection(**params_connection)

        result ='RFC_SYSTEM_INFO')

        pp = PrettyPrinter(indent=4)

    except CommunicationError:
        print u"Could not connect to server."
    except LogonError:
        print u"Could not log in. Wrong credentials?"
    except (ABAPApplicationError, ABAPRuntimeError):
        print u"An error occurred."

if __name__ == '__main__':

Now, if you run:


You should get a response with system information, like this:

    u'RFCSI_EXPORT': {   u'RFCCHARTYP': u'4103',
                         u'RFCDATABS': u'NPL',
                         u'RFCDAYST': u'',
                         u'RFCDBHOST': u'WDFLBMD6865',
                         u'RFCDBSYS': u'ADABAS D',
                         u'RFCDEST': u'wdflbmd6865_NPL_00',
                         u'RFCFLOTYP': u'IE3',
                         u'RFCHOST': u'wdflbmd6',
                         u'RFCHOST2': u'wdflbmd6865',
                         u'RFCINTTYP': u'LIT',
                         u'RFCIPADDR': u'',
                         u'RFCIPV6ADDR': u'',
                         u'RFCKERNRL': u'740',
                         u'RFCMACH': u'  390',
                         u'RFCOPSYS': u'Linux',
                         u'RFCPROTO': u'011',
                         u'RFCSAPRL': u'740',
                         u'RFCSI_RESV': u'',
                         u'RFCSYSID': u'NPL',
                         u'RFCTZONE': u'     0'}}

It works! And how easy was that?


  1. I've made some assumptions in this document. One assumption is that you're wanting the 32-bit version of the software (this will still work on 64-bit systems!)
  2. You really should investigate using pip for installing further Python packages. For installing pip on windows see this link
  3. ...and you owe it to yourself to install virtualenv which allows you to install Python modules independently from the global Python install! See the same link as above.
  4. Here is a binary egg file for python-sapnwrfc (md5 358ca360a290e52c5a55d90fb3998abb) (This file is Piers Harding's wrapper module which was an earlier module that we used before PyRFC came along, in case you'd rather use his module instead of PyRFC).