Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →How to Visualize Cvent Data in Python with pandas
Use pandas and other modules to analyze and visualize live Cvent data in Python.
The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Python Connector for Cvent, the pandas & Matplotlib modules, and the SQLAlchemy toolkit, you can build Cvent-connected Python applications and scripts for visualizing Cvent data. This article shows how to use the pandas, SQLAlchemy, and Matplotlib built-in functions to connect to Cvent data, execute queries, and visualize the results.
With built-in optimized data processing, the CData Python Connector offers unmatched performance for interacting with live Cvent data in Python. When you issue complex SQL queries from Cvent, the driver pushes supported SQL operations, like filters and aggregations, directly to Cvent and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations).
Connecting to Cvent Data
Connecting to Cvent 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 authenticate to Cvent, you must create a workspace and an OAuth application.
Creating a Workspace
To create a workspace:
- Sign into Cvent and navigate to App Switcher (the blue button in the upper right corner of the page) >> Admin.
- In the Admin menu, navigate to Integrations >> REST API.
- A new tab launches for Developer Management. Click on Manage API Access in the new tab.
- Create a Workspace and name it. Select the scopes you would like your developers to have access to. Scopes control what data domains the developer can access.
- Choose All to allow developers to choose any scope, and any future scopes added to the REST API.
- Choose Custom to limit the scopes developers can choose for their OAuth apps to selected scopes. To access all tables exposed by the driver, you need to set the following scopes:
event/attendees:read event/attendees:write event/contacts:read event/contacts:write event/custom-fields:read event/custom-fields:write event/events:read event/events:write event/sessions:delete event/sessions:read event/sessions:write event/speakers:delete event/speakers:read event/speakers:write budget/budget-items:read budget/budget-items:write exhibitor/exhibitors:read exhibitor/exhibitors:write survey/surveys:read survey/surveys:write
Creating an OAuth Application
After you have set up a Workspace and invited them, developers can sign up and create a custom OAuth app. See the Creating a Custom OAuth Application section in the Help documentation for more information.
Connecting to Cvent
After creating an OAuth application, set the following connection properties to connect to Cvent:
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
- OAuthClientId: The Client ID associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
- OAuthClientSecret: The Client secret associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
Follow the procedure below to install the required modules and start accessing Cvent through Python objects.
Install Required Modules
Use the pip utility to install the pandas & Matplotlib modules and the SQLAlchemy toolkit:
pip install pandas pip install matplotlib pip install sqlalchemy
Be sure to import the module with the following:
import pandas import matplotlib.pyplot as plt from sqlalchemy import create_engine
Visualize Cvent Data in Python
You can now connect with a connection string. Use the create_engine function to create an Engine for working with Cvent data.
engine = create_engine("cvent:///?OAuthClientId=MyOAuthClientId&OAuthClientSecret=MyOAuthClientSecret&InitiateOAuth=GETANDREFRESH&OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")
Execute SQL to Cvent
Use the read_sql function from pandas to execute any SQL statement and store the resultset in a DataFrame.
df = pandas.read_sql("SELECT Id, Title FROM Events WHERE Virtual = 'true'", engine)
Visualize Cvent Data
With the query results stored in a DataFrame, use the plot function to build a chart to display the Cvent data. The show method displays the chart in a new window.
df.plot(kind="bar", x="Id", y="Title") plt.show()
Free Trial & More Information
Download a free, 30-day trial of the CData Python Connector for Cvent to start building Python apps and scripts with connectivity to Cvent data. Reach out to our Support Team if you have any questions.
Full Source Code
import pandas import matplotlib.pyplot as plt from sqlalchemy import create_engin engine = create_engine("cvent:///?OAuthClientId=MyOAuthClientId&OAuthClientSecret=MyOAuthClientSecret&InitiateOAuth=GETANDREFRESH&OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt") df = pandas.read_sql("SELECT Id, Title FROM Events WHERE Virtual = 'true'", engine) df.plot(kind="bar", x="Id", y="Title") plt.show()