Ready to get started?

Download a free trial of the Dynamics NAV Connector to get started:

 Download Now

Learn more:

Dynamics NAV Icon Dynamics NAV Python Connector

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

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



Create ETL applications and real-time data pipelines for Dynamics NAV 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 Dynamics NAV and the petl framework, you can build Dynamics NAV-connected applications and pipelines for extracting, transforming, and loading Dynamics NAV data. This article shows how to connect to Dynamics NAV with the CData Python Connector and use petl and pandas to extract, transform, and load Dynamics NAV data.

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

Connecting to Dynamics NAV Data

Connecting to Dynamics NAV 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.

Before you can connect, OData Services will need to be enabled on the server. Once OData Services are enabled, you will be able to query any Services that are published on the server.

The User and Password properties, under the Authentication section, must be set to valid Dynamics NAV user credentials. In addition, you will need to specify a URL to a valid Dynamics NAV server organization root and a ServerInstance. If there is not a Service Default Company for the server, you will need to set the Company as well.

After installing the CData Dynamics NAV Connector, follow the procedure below to install the other required modules and start accessing Dynamics NAV 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 Dynamics NAV 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.dynamicsnav as mod

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

cnxn = mod.connect("http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;")

Create a SQL Statement to Query Dynamics NAV

Use SQL to create a statement for querying Dynamics NAV. In this article, we read data from the Customer entity.

sql = "SELECT Name, Prices_Including_VAT FROM Customer WHERE Name = 'Bob'"

Extract, Transform, and Load the Dynamics NAV Data

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

Loading Dynamics NAV Data into a CSV File

table1 = etl.fromdb(cnxn,sql)

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

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

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

Adding New Rows to Dynamics NAV

table1 = [ ['Name','Prices_Including_VAT'], ['NewName1','NewPrices_Including_VAT1'], ['NewName2','NewPrices_Including_VAT2'], ['NewName3','NewPrices_Including_VAT3'] ]

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

With the CData Python Connector for Dynamics NAV, you can work with Dynamics NAV 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 Dynamics NAV to start building Python apps and scripts with connectivity to Dynamics NAV 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.dynamicsnav as mod

cnxn = mod.connect("http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;")

sql = "SELECT Name, Prices_Including_VAT FROM Customer WHERE Name = 'Bob'"

table1 = etl.fromdb(cnxn,sql)

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

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

table3 = [ ['Name','Prices_Including_VAT'], ['NewName1','NewPrices_Including_VAT1'], ['NewName2','NewPrices_Including_VAT2'], ['NewName3','NewPrices_Including_VAT3'] ]

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