Ready to get started?

Learn more about the CData Python Connector for Workday or download a free trial:

Download Now

Use SQLAlchemy ORMs to Access Workday Data in Python

The CData Python Connector for Workday enables you to create Python applications and scripts that use SQLAlchemy Object-Relational Mappings of Workday data.

The rich ecosystem of Python modules lets you get to work quickly and integrate your systems effectively. With the CData Python Connector for Workday and the SQLAlchemy toolkit, you can build Workday-connected Python applications and scripts. This article shows how to use SQLAlchemy to connect to Workday data to query Workday data.

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

Connecting to Workday Data

Connecting to Workday 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.

To connect, there are three pieces of information required: Authentication, API URL, and WSDL URL.

Authentication

To authenticate, specify your User and Password. Note that you must append your Tenant to your User separated by an '@' character. For instance, if you normally log in with 'geraldg' and your Tenant is 'mycompany_mc1', then your User should be specified as 'geraldg@mycompany_mc1'.

API URL

The API URL may be specified either directly via APIURL, or it may be constructed from the Tenant, Service, and Host. The APIURL is constructed in the following format: <Host>/ccx/service/<Tenant>/<Service>.

WSDL URL

The WSDLURL may be specified in its entirety, or may be constructed from the Service and WSDLVersion connection properties. The WSDLURL is constructed in the following format: https://community.workday.com/sites/default/files/file-hosting/productionapi/<Service>/<WSDLVersion>/<Service>.wsdl

Follow the procedure below to install SQLAlchemy and start accessing Workday through Python objects.

Install Required Modules

Use the pip utility to install the SQLAlchemy toolkit:

pip install sqlalchemy

Be sure to import the module with the following:

import sqlalchemy

Model Workday Data in Python

You can now connect with a connection string. Use the create_engine function to create an Engine for working with Workday data.

engine = create_engine("workday///?User=myuser&Password=mypassword&Tenant=mycompany_gm1&Host=https://wd3-impl-services1.workday.com")

Declare a Mapping Class for Workday Data

After establishing the connection, declare a mapping class for the table you wish to model in the ORM (in this article, we will model the Workers table). Use the sqlalchemy.ext.declarative.declarative_base function and create a new class with some or all of the fields (columns) defined.

base = declarative_base()
class Workers(base):
	__tablename__ = "Workers"
	Worker_Reference_WID = Column(String,primary_key=True)
	Legal_Name_Last_Name = Column(String)
	...

Query Workday Data

With the mapping class prepared, you can use a session object to query the data source. After binding the Engine to the session, provide the mapping class to the session query method.

Using the query Method

engine = create_engine("workday///?User=myuser&Password=mypassword&Tenant=mycompany_gm1&Host=https://wd3-impl-services1.workday.com")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query(Workers).filter_by(Legal_Name_Last_Name="Morgan"):
	print("Worker_Reference_WID: ", instance.Worker_Reference_WID)
	print("Legal_Name_Last_Name: ", instance.Legal_Name_Last_Name)
	print("---------")

Alternatively, you can use the execute method with the appropriate table object. The code below works with an active session.

Using the execute Method

Workers_table = Workers.metadata.tables["Workers"]
for instance in session.execute(Workers_table.select().where(Workers_table.c.Legal_Name_Last_Name == "Morgan")):
	print("Worker_Reference_WID: ", instance.Worker_Reference_WID)
	print("Legal_Name_Last_Name: ", instance.Legal_Name_Last_Name)
	print("---------")

For examples of more complex querying, including JOINs, aggregations, limits, and more, refer to the Help documentation for the extension.

Free Trial & More Information

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