Ready to get started?

Download a free trial of the WooCommerce Connector to get started:

 Download Now

Learn more:

WooCommerce Icon WooCommerce Python Connector

Python Connector Libraries for WooCommerce Data Connectivity. Integrate WooCommerce with popular Python tools like Pandas, SQLAlchemy, Dash & petl.

How to Build an ETL App for WooCommerce Data in Python with CData



Create ETL applications and real-time data pipelines for WooCommerce data in Python with petl.

The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Python Connector for WooCommerce and the petl framework, you can build WooCommerce-connected applications and pipelines for extracting, transforming, and loading WooCommerce data. This article shows how to connect to WooCommerce with the CData Python Connector and use petl and pandas to extract, transform, and load WooCommerce data.

With built-in, optimized data processing, the CData Python Connector offers unmatched performance for interacting with live WooCommerce data in Python. When you issue complex SQL queries from WooCommerce, the driver pushes supported SQL operations, like filters and aggregations, directly to WooCommerce and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations).

Connecting to WooCommerce Data

Connecting to WooCommerce data looks just like connecting to any relational data source. Create a connection string using the required connection properties. For this article, you will pass the connection string as a parameter to the create_engine function.

WooCommerce supports the following authentication methods: one-legged OAuth1.0 Authentication and standard OAuth2.0 Authentication.

Connecting using one-legged OAuth 1.0 Authentication

Specify the following properties (NOTE: the below credentials are generated from WooCommerce settings page and should not be confused with the credentials generated by using WordPress OAuth2.0 plugin):

  • ConsumerKey
  • ConsumerSecret

Connecting using WordPress OAuth 2.0 Authentication

After having configured the plugin, you may connect to WooCommerce by providing the following connection properties:

  • OAuthClientId
  • OAuthClientSecret
  • CallbackURL
  • InitiateOAuth - Set this to either GETANDREFRESH or REFRESH

In either case, you will need to set the Url property to the URL of the WooCommerce instance.

After installing the CData WooCommerce Connector, follow the procedure below to install the other required modules and start accessing WooCommerce through Python objects.

Install Required Modules

Use the pip utility to install the required modules and frameworks:

pip install petl
pip install pandas

Build an ETL App for WooCommerce Data in Python

Once the required modules and frameworks are installed, we are ready to build our ETL app. Code snippets follow, but the full source code is available at the end of the article.

First, be sure to import the modules (including the CData Connector) with the following:

import petl as etl
import pandas as pd
import cdata.woocommerce as mod

You can now connect with a connection string. Use the connect function for the CData WooCommerce Connector to create a connection for working with WooCommerce data.

cnxn = mod.connect("Url=https://example.com/; ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad; ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5; InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")")

Create a SQL Statement to Query WooCommerce

Use SQL to create a statement for querying WooCommerce. In this article, we read data from the Orders entity.

sql = "SELECT ParentId, Total FROM Orders WHERE ParentId = '3'"

Extract, Transform, and Load the WooCommerce Data

With the query results stored in a DataFrame, we can use petl to extract, transform, and load the WooCommerce data. In this example, we extract WooCommerce data, sort the data by the Total column, and load the data into a CSV file.

Loading WooCommerce Data into a CSV File

table1 = etl.fromdb(cnxn,sql)

table2 = etl.sort(table1,'Total')

etl.tocsv(table2,'orders_data.csv')

In the following example, we add new rows to the Orders table.

Adding New Rows to WooCommerce

table1 = [ ['ParentId','Total'], ['NewParentId1','NewTotal1'], ['NewParentId2','NewTotal2'], ['NewParentId3','NewTotal3'] ]

etl.appenddb(table1, cnxn, 'Orders')

With the CData Python Connector for WooCommerce, you can work with WooCommerce data just like you would with any database, including direct access to data in ETL packages like petl.

Free Trial & More Information

Download a free, 30-day trial of the CData Python Connector for WooCommerce to start building Python apps and scripts with connectivity to WooCommerce data. Reach out to our Support Team if you have any questions.



Full Source Code


import petl as etl
import pandas as pd
import cdata.woocommerce as mod

cnxn = mod.connect("Url=https://example.com/; ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad; ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5; InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")")

sql = "SELECT ParentId, Total FROM Orders WHERE ParentId = '3'"

table1 = etl.fromdb(cnxn,sql)

table2 = etl.sort(table1,'Total')

etl.tocsv(table2,'orders_data.csv')

table3 = [ ['ParentId','Total'], ['NewParentId1','NewTotal1'], ['NewParentId2','NewTotal2'], ['NewParentId3','NewTotal3'] ]

etl.appenddb(table3, cnxn, 'Orders')