This notebook demonstrates how to use the DataLab Python SDK to add files to a DataLab server.

Setup

# Import the gfhub
import gfhub
from pathlib import Path

Create a Sample CSV File

Let's create a simple CSV file to upload:

# Create a sample CSV file
sample_data = """name,age,city
Alice,30,New York
Bob,25,San Francisco
Charlie,35,Los Angeles
Diana,28,Chicago
Eve,32,Boston
"""

# Write to file
sample_file = Path("sample_data.csv")
sample_file.write_text(sample_data)

print(f"Created {sample_file} ({sample_file.stat().st_size} bytes)")
Created sample_data.csv (107 bytes)

Initialize the Client

Create a client instance

# Connect to local DataLab server (default)
client = gfhub.Client()

# Or specify a custom URL:
# client = gfhub.Client("http://example.com:8080")

Add the File

Add the CSV file to DataLab:

# Add the file (trigger_pipelines defaults to True, so we only specify if we want False)
result = client.add_file(str(sample_file), tags=["test"])
print(result)
{'id': '019bbc08-a07a-78e0-b98b-044d1c39a744', 'name': 'sample_data.csv', 'original_name': 'sample_data.csv', 'mime_type': 'text/csv', 'status': 'Available'}

Cleanup

sample_file.unlink(missing_ok=True)