Ready to get started?

Learn more about Sage US Connectivity Solutions

Learn More

Using the CData ODBC Driver for Sage US in PyCharm

Connect to Sage US as an ODBC data source in PyCharm using the CData ODBC Driver for Sage US.

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 Sage US 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 Sage US 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 Sage US

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.

The Application Id and Company Name connection string options are required to connect to Sage as a data source. You can obtain an Application Id by contacting Sage directly to request access to the Sage 50 SDK.

Sage must be installed on the machine. The Sage.Peachtree.API.dll and Sage.Peachtree.API.Resolver.dll assemblies are required. These assemblies are installed with Sage in C:\Program Files\Sage\Peachtree\API\. Additionally, the Sage SDK requires .NET Framework 4.0 and is only compatible with 32-bit applications. To use the Sage SDK in Visual Studio, set the Platform Target property to "x86" in Project -> Properties -> Build.

You must authorize the application to access company data: To authorize your application to access Sage, restart the Sage application, open the company you want to access, and connect with your application. You will then be prompted to set access permissions for the application in the resulting dialog.

While the compiled executable will require authorization only once, during development you may need to follow this process to reauthorize a new build. To avoid restarting the Sage application when developing with Visual Studio, click Build -> Configuration Manager and uncheck "Build" for your project.

Below is the syntax for a DSN:

[CData Sage50US Source] Driver = CData ODBC Driver for Sage US Description = My Description ApplicationId = 8dfafu4V4ODmh1fM0xx CompanyName = Bellwether Garden Supply - Premium

Execute SQL to Sage US

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 Sage50US};ApplicationId = 8dfafu4V4ODmh1fM0xx;CompanyName = Bellwether Garden Supply - Premium;') cursor = cnxn.cursor() cursor.execute("SELECT Name, LastInvoiceAmount FROM Customer WHERE Name = 'ALDRED'") rows = cursor.fetchall() for row in rows: print(row.Name, row.LastInvoiceAmount)

After connecting to Sage US in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to Sage US 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.