![]() |
VOOZH | about |
The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Python Connector for Exchange and the petl framework, you can build Microsoft Exchange-connected applications and pipelines for extracting, transforming, and loading Microsoft Exchange data. This article shows how to connect to Microsoft Exchange with the CData Python Connector and use petl and pandas to extract, transform, and load Microsoft Exchange data.
With built-in, optimized data processing, the CData Python Connector offers unmatched performance for interacting with live Microsoft Exchange data in Python. When you issue complex SQL queries from Microsoft Exchange, the driver pushes supported SQL operations, like filters and aggregations, directly to Microsoft Exchange and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations).
Connecting to Microsoft Exchange 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.
Specify the User and Password to connect to Exchange. Additionally, specify the address of the Exchange server you are connecting to and the Platform associated with the server.
After installing the CData Microsoft Exchange Connector, follow the procedure below to install the other required modules and start accessing Microsoft Exchange through Python objects.
Use the pip utility to install the required modules and frameworks:
pip install petl pip install pandas
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.exchange as mod
You can now connect with a connection string. Use the connect function for the CData Microsoft Exchange Connector to create a connection for working with Microsoft Exchange data.
cnxn = mod.connect("User='[email protected]';Password='myPassword';Server='https://outlook.office365.com/EWS/Exchange.asmx';Platform='Exchange_Online';")
Use SQL to create a statement for querying Microsoft Exchange. In this article, we read data from the Contacts entity.
sql = "SELECT GivenName, Size FROM Contacts WHERE BusinnessAddress_City = 'Raleigh'"
With the query results stored in a DataFrame, we can use petl to extract, transform, and load the Microsoft Exchange data. In this example, we extract Microsoft Exchange data, sort the data by the Size column, and load the data into a CSV file.
table1 = etl.fromdb(cnxn,sql) table2 = etl.sort(table1,'Size') etl.tocsv(table2,'contacts_data.csv')
In the following example, we add new rows to the Contacts table.
table1 = [ ['GivenName','Size'], ['NewGivenName1','NewSize1'], ['NewGivenName2','NewSize2'], ['NewGivenName3','NewSize3'] ] etl.appenddb(table1, cnxn, 'Contacts')
With the CData Python Connector for Exchange, you can work with Microsoft Exchange data just like you would with any database, including direct access to data in ETL packages like petl.
Download a free, 30-day trial of the CData Python Connector for Exchange to start building Python apps and scripts with connectivity to Microsoft Exchange data. Reach out to our Support Team if you have any questions.
import petl as etl
import pandas as pd
import cdata.exchange as mod
cnxn = mod.connect("User='[email protected]';Password='myPassword';Server='https://outlook.office365.com/EWS/Exchange.asmx';Platform='Exchange_Online';")
sql = "SELECT GivenName, Size FROM Contacts WHERE BusinnessAddress_City = 'Raleigh'"
table1 = etl.fromdb(cnxn,sql)
table2 = etl.sort(table1,'Size')
etl.tocsv(table2,'contacts_data.csv')
table3 = [ ['GivenName','Size'], ['NewGivenName1','NewSize1'], ['NewGivenName2','NewSize2'], ['NewGivenName3','NewSize3'] ]
etl.appenddb(table3, cnxn, 'Contacts')
Download a Community License of the Exchange Connector to get started:
Download NowLearn more:
👁 Microsoft Exchange IconPython Connector Libraries for Microsoft Exchange Data Connectivity. Integrate Microsoft Exchange with popular Python tools like Pandas, SQLAlchemy, Dash & petl.