Skip to main content

XASE Sheets SDK - Python

Official Python SDK for XASE Sheets - Secure Data Marketplace Platform.

Installation

pip install xase-sheets

Quick Start

from xase import XaseClient

# Initialize client
client = XaseClient(api_key='your-api-key')

# List datasets
result = client.list_datasets()
print(f"Found {result['total']} datasets")

# Create a lease
lease = client.create_lease(
    dataset_id='dataset-id',
    duration=3600,  # 1 hour
    purpose='AI model training'
)

print(f"Access token: {lease.accessToken}")

Features

  • ✅ Full type hints support
  • ✅ Synchronous and asynchronous API
  • ✅ Automatic retries and error handling
  • ✅ Context manager support
  • ✅ Comprehensive error messages
  • ✅ Python 3.8+ support

API Reference

Client Initialization

from xase import XaseClient

client = XaseClient(
    api_key='your-api-key',      # Required
    base_url='https://api.xase.ai',  # Optional
    timeout=30,                   # Optional (seconds)
)

Datasets

List Datasets

result = client.list_datasets(
    page=1,
    limit=20,
    data_type='AUDIO'  # Optional filter
)

for dataset in result['datasets']:
    print(f"{dataset['name']}: {dataset['size']} bytes")

Get Dataset

dataset = client.get_dataset('dataset-id')
print(f"Dataset: {dataset.name}")
print(f"Type: {dataset.dataType}")
print(f"Size: {dataset.size} bytes")

Create Dataset

dataset = client.create_dataset(
    name='My Dataset',
    data_type='AUDIO',
    description='Audio dataset for speech recognition',
    tags=['speech', 'english']
)

Update Dataset

updated = client.update_dataset(
    'dataset-id',
    description='Updated description',
    tags=['speech', 'english', 'updated']
)

Delete Dataset

client.delete_dataset('dataset-id')

Leases

Create Lease

lease = client.create_lease(
    dataset_id='dataset-id',
    duration=3600,  # seconds
    purpose='Model training'
)

print(f"Lease ID: {lease.id}")
print(f"Access token: {lease.accessToken}")
print(f"Expires: {lease.endTime}")

Get Lease

lease = client.get_lease('lease-id')
print(f"Status: {lease.status}")

List Leases

result = client.list_leases(
    page=1,
    limit=20,
    status='ACTIVE'
)

for lease in result['leases']:
    print(f"Lease {lease['id']}: {lease['status']}")

Revoke Lease

client.revoke_lease('lease-id')

Renew Lease

renewed = client.renew_lease('lease-id', duration=3600)
print(f"New expiry: {renewed.endTime}")

Policies

Create Policy

policy = client.create_policy(
    name='Strict Access Policy',
    dataset_id='dataset-id',
    rules={
        'maxDuration': 7200,
        'watermarkRequired': True,
        'allowedPurposes': ['research', 'training']
    }
)

Get Policy

policy = client.get_policy('policy-id')
print(f"Policy: {policy.name}")
print(f"Active: {policy.active}")

List Policies

result = client.list_policies(
    dataset_id='dataset-id',
    active=True
)

Update Policy

updated = client.update_policy(
    'policy-id',
    active=False
)

Delete Policy

client.delete_policy('policy-id')

Usage Tracking

Record Usage

client.record_usage(
    lease_id='lease-id',
    bytes_transferred=1024000,
    records_accessed=100
)

Get Usage

usage = client.get_usage(
    start_date='2024-01-01',
    end_date='2024-01-31'
)

for record in usage:
    print(f"Lease {record.leaseId}: {record.bytesTransferred} bytes")

Marketplace

List Offers

result = client.list_offers(
    page=1,
    limit=20,
    data_type='AUDIO'
)

Get Offer

offer = client.get_offer('offer-id')
print(f"Price: {offer.price} {offer.currency}")

Request Access

request = client.request_access(
    offer_id='offer-id',
    purpose='Research project on speech recognition'
)
print(f"Request ID: {request.id}")
print(f"Status: {request.status}")

Search Marketplace

results = client.search_marketplace(
    'speech recognition',
    data_type='AUDIO',
    min_size=1000000
)

Webhooks

Create Webhook

webhook = client.create_webhook(
    url='https://your-domain.com/webhook',
    events=['lease.created', 'lease.expired'],
    secret='your-webhook-secret'
)

List Webhooks

webhooks = client.list_webhooks()
for webhook in webhooks:
    print(f"Webhook {webhook.id}: {webhook.url}")

Delete Webhook

client.delete_webhook('webhook-id')

Health Check

health = client.health()
print(f"API Status: {health['status']}")

Error Handling

from xase import XaseClient
from xase.exceptions import XaseAPIError, XaseAuthError, XaseNotFoundError

client = XaseClient(api_key='your-api-key')

try:
    dataset = client.get_dataset('invalid-id')
except XaseNotFoundError:
    print("Dataset not found")
except XaseAuthError:
    print("Invalid API key")
except XaseAPIError as e:
    print(f"API error: {e}")
    print(f"Status code: {e.status_code}")
    print(f"Response: {e.response}")

Context Manager

from xase import XaseClient

with XaseClient(api_key='your-api-key') as client:
    datasets = client.list_datasets()
    print(f"Found {datasets['total']} datasets")
# Session automatically closed

Type Hints

from xase import XaseClient, Dataset, Lease, Policy
from typing import List

client = XaseClient(api_key='key')

# Full type hints
dataset: Dataset = client.get_dataset('id')
lease: Lease = client.create_lease(dataset_id='id')

Examples

Complete Workflow

from xase import XaseClient

def main():
    client = XaseClient(api_key='your-api-key')
    
    # 1. Create a dataset
    dataset = client.create_dataset(
        name='Speech Dataset',
        data_type='AUDIO',
        description='English speech samples'
    )
    print(f"Created dataset: {dataset.id}")
    
    # 2. Create access policy
    policy = client.create_policy(
        name='Research Access',
        dataset_id=dataset.id,
        rules={
            'maxDuration': 7200,
            'watermarkRequired': True,
            'allowedPurposes': ['research']
        }
    )
    print(f"Created policy: {policy.id}")
    
    # 3. Create lease
    lease = client.create_lease(
        dataset_id=dataset.id,
        duration=3600,
        purpose='Speech recognition research'
    )
    print(f"Access token: {lease.accessToken}")
    
    # 4. Record usage
    client.record_usage(
        lease_id=lease.id,
        bytes_transferred=5000000,
        records_accessed=500
    )
    
    # 5. Get usage stats
    usage = client.get_usage()
    total_bytes = sum(u.bytesTransferred for u in usage)
    print(f"Total bytes transferred: {total_bytes}")

if __name__ == '__main__':
    main()

Batch Operations

from xase import XaseClient

client = XaseClient(api_key='your-api-key')

# Create multiple datasets
datasets = []
for i in range(5):
    dataset = client.create_dataset(
        name=f'Dataset {i+1}',
        data_type='AUDIO',
        description=f'Dataset number {i+1}'
    )
    datasets.append(dataset)
    print(f"Created: {dataset.name}")

# Create leases for all datasets
leases = []
for dataset in datasets:
    lease = client.create_lease(
        dataset_id=dataset.id,
        duration=3600
    )
    leases.append(lease)
    print(f"Lease created for {dataset.name}")

Error Recovery

from xase import XaseClient
from xase.exceptions import XaseAPIError
import time

client = XaseClient(api_key='your-api-key')

def create_lease_with_retry(dataset_id, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.create_lease(dataset_id=dataset_id)
        except XaseAPIError as e:
            if e.status_code == 429:  # Rate limit
                wait_time = 2 ** attempt  # Exponential backoff
                print(f"Rate limited, waiting {wait_time}s...")
                time.sleep(wait_time)
            else:
                raise
    raise Exception("Max retries exceeded")

lease = create_lease_with_retry('dataset-id')

Environment Variables

# .env
XASE_API_KEY=your-api-key
XASE_BASE_URL=https://api.xase.ai
import os
from xase import XaseClient

client = XaseClient(
    api_key=os.getenv('XASE_API_KEY'),
    base_url=os.getenv('XASE_BASE_URL', 'https://api.xase.ai')
)

Development

Install Development Dependencies

pip install -e ".[dev]"

Run Tests

pytest
pytest --cov=xase tests/

Code Formatting

black src/
isort src/
flake8 src/
mypy src/

License

MIT

Support

Contributing

Contributions are welcome! Please read our contributing guidelines.

Changelog

See CHANGELOG.md for version history.

Metadata

Release files for xase-sheets 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xase-sheets 2.0.1
File Size Uploaded Provenance
xase_sheets-2.0.1.tar.gz 13.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xase-sheets 2.0.1
File Interpreter ABI Platform
xase_sheets-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / xase_sheets-2.0.1.tar.gz

Download URL xase_sheets-2.0.1.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a69726d4c43da3a259cf39e323ec30bfc62c00994c29a94c6e50dd0639a51cea
BLAKE2b-256 checksum
How to use checksums
354b69af1c3d92b71898a64acc2c62c58aee56f76ab4311cc7a513e209dccfdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / xase_sheets-2.0.1-py3-none-any.whl

Download URL xase_sheets-2.0.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be47f9ed52d7c045512cc06983bba57f25dedfda6dd5b81fc3e503fd29ec9295
BLAKE2b-256 checksum
How to use checksums
c224836e9e059ebcebf21d0e8d14368a4d65e8fd6972534cc98486693d3434c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Security for xase-sheets 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page