Ready to get started?

Download a free trial of the SAP Netweaver Gateway ODBC Driver to get started:

 Download Now

Learn more:

SAP Netweaver Gateway Icon SAP Netweaver Gateway ODBC Driver

The SAP Netweaver Gateway ODBC Driver is a powerful tool that allows you to connect with live data from SAP Netweaver Gateway, directly from any applications that support ODBC connectivity.

Access SAP Netweaver Gateway data like you would a database - read, write, and update SAP Netweaver Gateway Entities, etc. through a standard ODBC Driver interface.

Using the CData ODBC Driver for SAP Netweaver Gateway in PyCharm



Connect to SAP Netweaver Gateway as an ODBC data source in PyCharm using the CData ODBC Driver for SAP Netweaver Gateway.

The CData ODBC Drivers can be used in any environment that supports loading an ODBC Driver. In this tutorial we will explore using the CData ODBC Driver for SAP Netweaver Gateway from within PyCharm. Included are steps for adding the CData ODBC Driver as a data source, as well as basic PyCharm code to query the data source and display results.

To begin, this tutorial will assume that you have already installed the CData ODBC Driver for SAP Netweaver Gateway as well as PyCharm.

Add Pyodbc to the Project

Follow the steps below to add the pyodbc module to your project.

  1. Click File -> Settings to open the project settings window.
  2. Click Project Interpreter from the Project: YourProjectName menu.
  3. To add pyodbc, click the + button and enter pyodbc.
  4. Click Install Package to install pyodbc.

Connect to SAP Netweaver Gateway

You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.

SAP Gateway allows both basic and OAuth 2.0 authentication. You can use basic authentication to connect to your own account, or you can use OAuth to enable other users to retrieve data from your service with their accounts. In addition to authenticating, set the following connection properties to access SAP Gateway tables.

  • Url: Set this to the URL of your environment, or to the full URL of the service. For example, the full URL might appear as: https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/. In this example, the environment URL would just be: https://sapes5.sapdevcenter.com.
  • Namespace: Set the appropriate Service Namespace. In the example above, IWBEP is the namespace. It is optional if the full URL to the service is specified.
  • Service: Set this to the service you want to retrieve data from. In the example above, the service is GWSAMPLE_BASIC. It is not required if the full URL is specified.

Authenticate via Basic Authentication

In basic authentication, you use your login credentials to connect. Set the following properties:

  • User: This is the username you use to log in to SAP Gateway.
  • Password: This is the password you use to log in to SAP Gateway.

Authenticate via OAuth Authentication

You can connect to SAP Gateway using the embedded OAuth connectivity (without setting any additional authentication connection properties). When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.

Below is the syntax for a DSN:

[CData SAPGateway Source] Driver = CData ODBC Driver for SAP Netweaver Gateway Description = My Description User = user Password = password URL = https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/

Execute SQL to SAP Netweaver Gateway

Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.

import pyodbc cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for SAPGateway};User = user;Password = password;URL = https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/;') cursor = cnxn.cursor() cursor.execute("SELECT ProductID, Quantity FROM SalesOrderLineItems WHERE Quantity = '15'") rows = cursor.fetchall() for row in rows: print(row.ProductID, row.Quantity)

After connecting to SAP Netweaver Gateway in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to SAP Netweaver Gateway data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.