Skip to main content

Python client library for the DataPress API

Project description

DataPress Python Client

A Python client library for interacting with the DataPress API.

Installation

pip install datapress

How to Use

Set your API credentials as environment variables:

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

Basic Usage

from datapress import DataPressClient

# Initialize client
client = DataPressClient()

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

# Get a dataset
dataset = client.get_dataset("ab12x")
print(f"Dataset: {dataset['title']}")

Renaming a Dataset

# Rename a dataset using patch operations
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 a new file to a dataset
result = client.upload_file(
    dataset_id="ab12x",
    file_path="data/sales.csv",
    # Optional parameters:
    title="Sales Data",
    description="Monthly sales figures",
    order=1,
    timeframe={"from": "2024-01", "to": "2025-04"}
)
print(f"File uploaded with ID: {result['resource_id']}")

Replacing a File

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

Uploading a File from S3

You can transfer a file from S3 to a dataset by passing your boto3.client instance to the upload_file_from_s3 method. This will download the file in 5MB chunks and incrementally upload it to the dataset.

import boto3

session = boto3.session.Session()
s3_client = session.client(
    "s3",
    # ... credentials, endpoints, regions etc
    aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
    aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
)

# Upload a file from S3 to a dataset
result = client.upload_file_from_s3(
    s3_client=s3_client,
    bucket="your-bucket-name",
    key="your-object-key",
    dataset_id="ab12x",
    # Optional parameters:
    resource_id="xyz",  # ID of existing file to replace
    title="Updated Spending Data",
    description="Monthly spending figures",
    order=1,
    timeframe={"from": "2024-01", "to": "2025-04"}
)
print(f"File uploaded from S3: {result['resource_id']}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datapress-1.3.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datapress-1.3.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file datapress-1.3.0.tar.gz.

File metadata

  • Download URL: datapress-1.3.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for datapress-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7892d6c21e7c1eb6fdff594c91e4b4c401035427ed661966ae6b77ff9571079d
MD5 db6e95506e8e25dbd1823f9a797e8bed
BLAKE2b-256 2d4e92dcd15732f3e706e70690620c9393d22f00bb59f86551454301e2b6c397

See more details on using hashes here.

File details

Details for the file datapress-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: datapress-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for datapress-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b1796b13540c4ec057c6b92fdde067ae23e9186449f6f41b43a5966c82e0c8e
MD5 01a9dc29491b262ad462eafb75f24fce
BLAKE2b-256 aac6f19728e6e1c6335e004744d9fa012ffc7a45786600c5340e77203137c913

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page