Query SAP database from Python? [closed]

Can Python be used to query a SAP database?


Asked by: Dexter905 | Posted: 30-11-2021






Answer 1

Python SAP RFC module seems inactive - last (insignificant ) commit 2 years ago - but may serve you:

Pysaprfc is a wrapper around SAP librfc (librfc32.dll on Windows, librfccm.so or librfc.so on Linux). It uses the excellent ctypes extension package by Thomas Heller to access librfc and to define SAP compatible datatypes.

Modern SAP versions go the Web Service way - you could build a SAP Web Service and consume it from Python.

With SAP NetWeaver, developers can connect applications and data sources to integrate processes using Web services.

In particular, developers can use one infrastructure to define, implement, and use Web services in an industry standards based way. SAP NetWeaver supports synchronous, asynchronous, stateful and stateless web service models - enabling developers to support different integration scenarios.

sapnwrfc supports this SAP NetWeaver functionality, supersedes the older RFC SDK, and is actively maintained.

Answered by: Ryan275 | Posted: 01-01-2022



Answer 2

Python RFC connector is now available as open source: PyRFC

Answered by: John163 | Posted: 01-01-2022



Answer 3

SAP now has a Python RFC connector called pyrfc. This supersedes sapnwrfc.

This can be found at: https://github.com/SAP/PyRFC

"The pyrfc Python package provides Python bindings for SAP NetWeaver RFC Library, for a comfortable way of calling ABAP modules from Python and Python modules from ABAP, via SAP Remote Function Call (RFC) protocol."

Answered by: Tess989 | Posted: 01-01-2022



Answer 4

If you're talking about (what used to be named) the SAP Database AKA SapDb, and is now MaxDB (for a while distributed also by MySql Inc, now again by SAP only -- and so named SAP MaxDB), it comes with several Python access modules, documented here.

This is the only meaning I can attach to "SAP as the database engine" -- that you want to access SAP MaxDB. Other answers make different assumptions and (I believe) are also correct... under those different assumptions.

Answered by: Cherry194 | Posted: 01-01-2022



Answer 5

Sap is NOT a database server. But with the Python SAP RFC module you can query most table quite easily. It is using some sap unsupported function ( that all the world is using). And this function has some limitation on field size and datatypes.

Answered by: Rafael849 | Posted: 01-01-2022



Answer 6

As stated above, when you just want to read tables or do RFC or BAPI calls, you can use CPython with the unmaintained Python SAP RFC module or Piers Harding's SAP RFC. The RFC calls to just read a table are RFC_GET_TABLE_ENTRIES or RFC_READ_TABLE, where the former is preferred, but also not released to customers.

For a more official way, you can use SAP's JCO connector with Jython or SAP's .Net Connector with Ironpython; both connectors can be downloaded from SAP's service marketplace and both allow to call the RFC functionality including the two calls listed above.

As also stated above, the way proposed by SAP to access backend functionality is via SAP's vast SOA infrastructure. Here you can use Jython with e.g. the Axis library or Ironpython with Microsofts WCF. Note, that the services provided by SAP obviously won't allow you to access the plain tables, instead you just can call, what a service provides. SAP already delivers about 3.000 services (see the ES Wiki on SDN), and creating your own service is in fact dead simple, once you have your business logic in a remote-enabled function module.

Answered by: Emily435 | Posted: 01-01-2022



Answer 7

Python is one of the most used object-oriented programming languages which is very easy to code and understand.

In order to use Python with SAP, we need to install Python SAP RFC module which is known as PyRFC. One of its available methods is RFC_READ_TABLE which can be called to read data from a table in SAP database.

Also, the PyRFC package provides various bindings which can be utilized to make calls either way. We can use to make calls either from ABAP modules to Python modules or the other way round. One can define equivalent SAP data types which are used in data exchange.

Also, we can create Web Service in Python which can be used for inter-communication. SAP NetWeaver is fully compatible with web services either state full or stateless.

Answered by: Roland904 | Posted: 01-01-2022



Similar questions

query url from mysql database using Python

I am trying to query a URL address from mysql database so that I can connect using this address and scrape a website. however I get an error Code: cnx = mysql.connector.connect(host=mysql_host, user=mysql_localhost_user, password=mysql_localhost_password, database=mysql_localhost_database) cursor = cnx.cursor() cursor.execute("SELECT url FROM masjid where ID =" + str(start) ) results2 = cursor.fetc...


python - My query doesn't show all results in my database

I currently have 3 records in my database that should show up, but I only see 2 of the 3. Just so you understand what is going on: subscriber 1 & 2 have campaign id 1 and subscriber 3 has campaign id 2 however both subscribers belong to campaigns created by the same account. So, what I am trying to accomplish is to show the account holder who has subscribed to their campaigns. Can someone tell m...


python - SQL database query issue

As part of a coding project I am doing, I have to create a program that will sort folders into 8 filing cabinets which have 3 shelves each organised in alphabetical order based on the surname (A,A,AB, BC,C,D, E,F,G, HIJ,L,M, M,M,MN, O,PQ,R, RS,S,S, T,UVW,WXYZ). The problem I am having is with a function I am writing so that I can call it at any point and input the details of the student and find out where the folder ...


python - Exec and query to database through ORM

Python 3.5.2 This is Django'd ORM syntax. But I think, the question is about Python. I have prepared rather a huge string with a chain of ORM queries. ORM is a wrapper for accessing data base. The plan was to execute it via 'exec'. Well, not working. Whereas the string itself looks correct. Below there is a model. Well, just plain code works well. And with exec it do...


Python pyqt database query on a qlist

If you please can help me, I would appreciate it I'm doing a query of sqlite3 and I want to show the result on a QListWidget for row in c.execute("SELECT * FROM typem WHERE Type LIKE ?",('%'+'b'+'%',)): test = '' test += str(row[1]) print test self.listWidget.addItems(test) On the "print teste" is showing this


python - How can I not need to query the database every time?

How can I not need to query the database every time? From the bellow snapshot: I have five tabs, name as: 云主机,云硬盘,云主机快照,云硬盘快照,安全组: And in the bottom of...


How to query MySQL database using API in python?

I have my data in database, and I want to build an API using python to query the database. What do I use or where do I even start ? I can connect to my database and pull the data. But I do not know how to build an API for other users to query the database


python SQL database query

The query below works fine, only instead of refreshing the fixed value of end of last month, I need to pass the variable my_date to the query, so that the code works dynamically. Could someone help? Here a sample code: import my_db import pandas as pd import datetime today = datetime.date.today() first = today.replace(day=1) lastMonth = first - datetime.timedelta(days=1) my_date = lastMonth.strf...


python - Query database with flask by table

I have a POSTGRES database that I already setup that has about a thousand or so tables (if there is a better way to organise this, that would be super helpful, I'm new to databases in general, but understand the basics). I am trying to use flask to setup an API which will eventually be used by my vue app (and also probably available to the community of interest at large). Ideally, I would like my...


Python database query

I am having a problem with SELECT operation during CRUD operations. I want to pull the query from the database and throw it into a table. Why is %s error here? Can you help me? @app.route('/Index') def querypage(): cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) error = '' if request.method == 'POST': PRODUCT = request.form['PRODUCT'] PRICE = request.form['PRICE'...


python - Query similar full text in database

I am trying to match an OCR'd letter against a boilerplate template that will be stored in a database. I know how to compare strings to get similarity but for obvious reasons, I don't want to iterate over the entire table to compare every object. Is there a way to create an integer representation of a string so that the db could be queried with a range? Ideally, I'd be able to take an OCR result of This 1s a s...


python - Sometimes can't delete an Oracle database row using Django

I have a unit test which contains the following line of code Site.objects.get(name="UnitTest").delete() and this has worked just fine until now. However, that statement is currently hanging. It'll sit there forever trying to execute the delete. If I just say print Site.objects.get(name="UnitTest") then it works, so I know that it can retrieve the site. ...


python - How do I test a django database schema?

I want to write tests that can show whether or not the database is in sync with my models.py file. Actually I have already written them, only to find out that django creates a new database each time the tests are run based on the models.py file. Is there any way I can make the models.py test use the existing database schema? The one that's in mysql/postgresql, and not the one that's in /myapp/models.py ?


python - Using user input to find information in a Mysql database

I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me?


python - Import XML into SQL database

I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? I know this ability is built into MySQL 6.0, but that is not an option right now because it is an alpha development rel...


python - Using 'old' database with django

I'm using a hand built (Postgres) database with Django. With "inspectdb" I was able to automatically create a model for it. The problem is that some tables have multiple primary keys (for many-to-many relations) and they are not accessible via Django. What's the best way to access these tables?


database - python orm

This is a newbie theory question - I'm just starting to use Python and looking into Django and orm. Question: If I develop my objects and through additional development modify the base object structures, inheritance, etc. - would Django's ORM solution modify the database automatically OR do I need to perform a conversion (if the app is live)? So, I start with a basic Phone app Object person: name, address, city, s...


python - Large Sqlite database search

How is it possible to implement an efficient large Sqlite db search (more than 90000 entries)? I'm using Python and SQLObject ORM: import re ... def search1(): cr = re.compile(ur'foo') for item in Item.select(): if cr.search(item.name) or cr.search(item.skim): print item.name This function runs in more than 30 seconds. How sh...


A database for python 3?

I'm coding a small piece of server software for the personal use of several users. Not hundreds, not thousands, but perhaps 3-10 at a time. Since it's a threaded server, SQLite doesn't work. It complains about threads like this: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140735085562848 and this is thread id 43...


python - URLs stored in database for Django site

I've produced a few Django sites but up until now I have been mapping individual views and URLs in urls.py. Now I've tried to create a small custom CMS but I'm having trouble with the URLs. I have a database table (SQLite3) which contains code for the pages like a column for header, one for right menu, one for content.... so on, so on. I also have a column for the URL. How do I get Django to call the information in...


python - Using Django database layer outside of Django?

I've got a nice database I've created in Django, and I'd like to interface with through some python scripts outside of my website stuff, so I'm curious if it's possible to use the Django database API outside of a Django site, and if so does anyone have any info on how it can be done? Google hasn't yielded many hits for this.


database - Problem opening berkeley db in python

I have problems opening a berkeley db in python using bdtables. As bdtables is used by the library I am using to access the database, I need it to work. The problem seems to be that the db environment I am trying to open (I got a copy of the database to open), is version 4.4 while libdb is version 4.6. I get the following error using bsddb.dbtables.bsdTableDB([dbname],[folder]): (-30972, "DB_VERSION...


database - Store simple user settings in Python

I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue. The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them. For example, userdb["bob"]["colour_scheme"] would have the value "b...


python - Sometimes can't delete an Oracle database row using Django

I have a unit test which contains the following line of code Site.objects.get(name="UnitTest").delete() and this has worked just fine until now. However, that statement is currently hanging. It'll sit there forever trying to execute the delete. If I just say print Site.objects.get(name="UnitTest") then it works, so I know that it can retrieve the site. ...


python - How do I test a django database schema?

I want to write tests that can show whether or not the database is in sync with my models.py file. Actually I have already written them, only to find out that django creates a new database each time the tests are run based on the models.py file. Is there any way I can make the models.py test use the existing database schema? The one that's in mysql/postgresql, and not the one that's in /myapp/models.py ?


python - Using user input to find information in a Mysql database

I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me?


python - Given an rpm package name, query the yum database for updates

I was imagining a 3-line Python script to do this but the yum Python API is impenetrable. Is this even possible? Is writing a wrapper for 'yum list package-name' the only way to do this?


python - Import XML into SQL database

I'm working with a 20 gig XML file that I would like to import into a SQL database (preferably MySQL, since that is what I am familiar with). This seems like it would be a common task, but after Googling around a bit I haven't been able to figure out how to do it. What is the best way to do this? I know this ability is built into MySQL 6.0, but that is not an option right now because it is an alpha development rel...


python - Using 'old' database with django

I'm using a hand built (Postgres) database with Django. With "inspectdb" I was able to automatically create a model for it. The problem is that some tables have multiple primary keys (for many-to-many relations) and they are not accessible via Django. What's the best way to access these tables?


python - How do I notify a process of an SQLite database change done in a different process?

Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player t...


database - python orm

This is a newbie theory question - I'm just starting to use Python and looking into Django and orm. Question: If I develop my objects and through additional development modify the base object structures, inheritance, etc. - would Django's ORM solution modify the database automatically OR do I need to perform a conversion (if the app is live)? So, I start with a basic Phone app Object person: name, address, city, s...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top