Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active December 14, 2023 05:41
Convert XML to CSV and CSV to XML in Python
# How to Convert CSV to XML in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.csv"
settings.format = "xml"
settings.output_path = "python-testing/output-sample-file.xml"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted large XML to CSV in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))

You can convert XML file to CSV and convert CSV to XML online in Python programmatically on the cloud. In this article, we will learn how to convert XML to CSV and CSV to XML online in Python using REST API.

The following topics shall be covered in this article:

  1. XML to CSV and CSV to XML Conversion API – Installation
  2. How to Convert XML to CSV in Python using REST API
  3. How to Convert CSV to XML in Python using REST API
# How to Convert XML to CSV Online in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.xml"
settings.format = "csv"
settings.output_path = "python-testing/output-sample-file.csv"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted XML file to CSV format in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_conversion_cloud
# Get client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Get File API configurations
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "InternalStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment