[ACCEPTED]-Query SAP database from Python?-pyrfc
Python SAP RFC module seems inactive - last (insignificant ) commit 2 years ago - but may 17 serve you:
Pysaprfc is a wrapper around SAP 16 librfc (librfc32.dll on Windows, librfccm.so 15 or librfc.so on Linux). It uses the excellent 14 ctypes extension package by Thomas Heller 13 to access librfc and to define SAP compatible 12 datatypes.
Modern SAP versions go the
Web Service way - you 11 could build a
SAP Web Service and consume it from
With 10 SAP NetWeaver, developers can connect applications 9 and data sources to integrate processes 8 using Web services.
In particular, developers 7 can use one infrastructure to define, implement, and 6 use Web services in an industry standards 5 based way. SAP NetWeaver supports synchronous, asynchronous, stateful 4 and stateless web service models - enabling 3 developers to support different integration 2 scenarios.
sapnwrfc supports this
SAP NetWeaver functionality, supersedes the 1 older RFC SDK, and is actively maintained.
Python RFC connector is now available as 1 open source: PyRFC
SAP now has a Python RFC connector called 7 pyrfc. This supersedes sapnwrfc.
This can 6 be found at: https://github.com/SAP/PyRFC
"The pyrfc Python package 5 provides Python bindings for SAP NetWeaver 4 RFC Library, for a comfortable way of calling 3 ABAP modules from Python and Python modules 2 from ABAP, via SAP Remote Function Call 1 (RFC) protocol."
If you're talking about (what used to be 9 named) the SAP Database AKA SapDb, and is now 8 MaxDB (for a while distributed also by MySql 7 Inc, now again by SAP only -- and so named 6 SAP MaxDB), it comes with several Python access modules, documented 5 here.
This is the only meaning I can attach to 4 "SAP as the database engine" -- that 3 you want to access SAP MaxDB. Other answers 2 make different assumptions and (I believe) are 1 also correct... under those different assumptions.
Sap is NOT a database server. But with the 5 Python SAP RFC module you can query most 4 table quite easily. It is using some sap 3 unsupported function ( that all the world 2 is using). And this function has some limitation 1 on field size and datatypes.
As stated above, when you just want to read 25 tables or do RFC or BAPI calls, you can 24 use CPython with the unmaintained Python 23 SAP RFC module or Piers Harding's SAP RFC. The 22 RFC calls to just read a table are RFC_GET_TABLE_ENTRIES 21 or RFC_READ_TABLE, where the former is preferred, but 20 also not released to customers.
For a more 19 official way, you can use SAP's JCO connector 18 with Jython or SAP's .Net Connector with 17 Ironpython; both connectors can be downloaded 16 from SAP's service marketplace and both 15 allow to call the RFC functionality including 14 the two calls listed above.
As also stated 13 above, the way proposed by SAP to access 12 backend functionality is via SAP's vast 11 SOA infrastructure. Here you can use Jython 10 with e.g. the Axis library or Ironpython 9 with Microsofts WCF. Note, that the services 8 provided by SAP obviously won't allow you 7 to access the plain tables, instead you 6 just can call, what a service provides. SAP 5 already delivers about 3.000 services (see 4 the ES Wiki on SDN), and creating your own 3 service is in fact dead simple, once you 2 have your business logic in a remote-enabled 1 function module.
Python is one of the most used object-oriented 17 programming languages which is very easy 16 to code and understand.
In order to use Python 15 with SAP, we need to install Python SAP 14 RFC module which is known as PyRFC. One 13 of its available methods is RFC_READ_TABLE 12 which can be called to read data from a 11 table in SAP database.
Also, the PyRFC package 10 provides various bindings which can be utilized 9 to make calls either way. We can use to 8 make calls either from ABAP modules to Python 7 modules or the other way round. One can 6 define equivalent SAP data types which are 5 used in data exchange.
Also, we can create 4 Web Service in Python which can be used 3 for inter-communication. SAP NetWeaver is 2 fully compatible with web services either 1 state full or stateless.
More Related questions