DataPress logo
Client Libraries

Python Client

Version:  1.0
Updated:  27th August 2025

Overview

The DataPress Python client provides a simple interface for interacting with the DataPress API. It handles authentication, chunked uploads, and provides client-side validation for common operations.

Installation

pip install datapress-client

Authentication

Set your API credentials as environment variables:

export DATAPRESS_API_KEY="your-api-key"
export DATAPRESS_URL="https://your-datapress-instance.com"

Basic Usage

Initialize the Client

from datapress import DataPressClient

# Initialize using environment variables
client = DataPressClient()

# Or pass credentials explicitly
client = DataPressClient(
    api_key="your-api-key",
    base_url="https://your-datapress-instance.com"
)

# Verify authentication
user_info = client.whoami()
print(f"Logged in as: {user_info['title']}")

Get Dataset Information

# Retrieve a dataset by ID
dataset = client.get_dataset("ab12x")
print(f"Dataset: {dataset['title']}")
print(f"Resources: {len(dataset['resources'])}")

Common Operations

Renaming a Dataset

Use JSON Patch operations to modify dataset metadata:

patch = [{"op": "replace", "path": "/title", "value": "New Dataset Name"}]
result = client.patch_dataset("ab12x", patch)
print(f"Dataset renamed to: {result['dataset']['title']}")

Adding a File

Upload new files using chunked uploads (automatically handles large files):

result = client.upload_file(
    dataset_id="ab12x",
    file_path="data/sales.csv",
    title="Sales Data",
    description="Monthly sales figures"
)
print(f"File uploaded with ID: {result['resource_id']}")

Replacing a File

Replace an existing file by providing its resource ID:

result = client.upload_file(
    dataset_id="ab12x",
    file_path="data/updated_sales.csv",
    resource_id="xyz",  # ID of existing file to replace
    title="Updated Sales Data"
)
print(f"File replaced: {result['resource_id']}")

Downloading Files

Download files with proper authentication:

file_data = client.download_file(
    dataset_id="ab12x",
    resource_id="xyz"
)

# Save to disk
with open("downloaded_file.csv", "wb") as f:
    f.write(file_data)

Advanced Usage

Batch Operations with Patch

Perform multiple updates in a single request:

patch_operations = [
    {"op": "replace", "path": "/title", "value": "Updated Title"},
    {"op": "replace", "path": "/description", "value": "Updated description"},
    {"op": "add", "path": "/links/new_link", "value": {
        "url": "https://example.com",
        "title": "Related Data"
    }}
]

result = client.patch_dataset("ab12x", patch_operations)

Remove Resources

Remove uploaded files using patch operations:

patch = [{"op": "remove", "path": "/resources/xyz89"}]
client.patch_dataset("ab12x", patch)

Error Handling

The client provides specific exception types for common errors:

from datapress.client import AuthenticationError, NotFoundError, PermissionError

try:
    dataset = client.get_dataset("ab12x")
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Dataset not found")
except PermissionError:
    print("No access to this dataset")

Source Code

The Python client is open source and available on GitHub. For development setup, testing, and detailed API reference, see the DEVELOPMENT.md file.