Skip to content

Uploading data with Python

This tutorial shows a simple example on how to upload files to Nexus using the Python programming language. A script like this can be useful to periodically upload data sources to Nexus that are not connected to the internet or that only need refreshing every once in a while.

Info

This tutorial assumes that you have:

  • Python installed on your computer
  • obtained a valid Nexus Web API token (with Data Supplier autorisation; see API Basics for more info)

Code

We use the 'requests' package for making the actual API calls.

import requests

url = "https://nexus.stellaspark.com/api/v1/uploads/?token={web_api_token}"

# Check which datasources in your Nexus world can be uploaded
r = requests.get(url)
datasources = r.json()

datasource_id = {datasource_id}  # Enter datasource ID to upload to

with open("path/to/my_file.csv","rb") as f:
    r = requests.post(url, files={"upload_file": f}, data={"datasource": datasource_id})
    r.raise_for_status()  # Throw an error if something goes wrong