Skip to main content

Official Python SDK for the DataFlare API

Project description

DF API Python SDK PyPI

The official Python SDK for the DataFlare API.

Features

  • Typed Models: Full Pydantic schemas mapping the Datasets API for rigid IDE autocompletion.
  • Connection Pools: Subclass optimized httpx logic reusing TCP connections seamlessly.
  • Resilient Requests: Automated retries (tenacity) wrapping Rate Limit and transient network faults over exponential backoffs.
  • Idiomatic Paginators: client.datasets.stream(...) automatically handles cursor injection iteratively returning stream chunks cleanly.
  • Memory-safe Source Retrieval: For pipelines feeding Large Language Models directly from data archives, effortlessly invoke download_file(...) natively chunking raw bytes down to the file system avoiding memory leaks.

Installation

# Standard REST client
pip install dataflare-sdk

# Include gRPC support
pip install "dataflare-sdk[grpc]"

Authentication

You will need a DataFlare API Key. The SDK provides two ways to configure it securely:

1. Auto-discover from Environment (Recommended)

Set the DF_API_KEY system environment variable (or load it from a local .env using python-dotenv):

export DF_API_KEY="dfk_abc123"

2. Direct Explicit Injection

If you pull secrets from an external vault, pass it directly into the constructor:

from df import DFClient
client = DFClient(api_key="dfk_your_secret_key...")

Quick Start

from df import DFClient, AuthenticationError

# Automatically discovers DF_API_KEY from the environment
try:
    with DFClient() as client:
        
        # Generator handles pagination constraints completely
        for doc in client.datasets.stream("legal", search_term="التأمين", limit=100):
            print(f"Doc category: {doc.category} | Title: {doc.title} | Summary: {doc.summary} | Decision: {doc.decision}")
            
            # Helper to download the raw File to disk natively
            if doc.source_url:
                client.datasets.download_file(
                    doc.source_url, 
                    destination=f"./archives/{doc.id}.pdf"
                )

except AuthenticationError:
    print("Invalid API Key.")

High-Performance gRPC Client

For environments requiring persistent connections and reduced latency, the SDK provides a dynamic gRPC client that works right out of the box using Server Reflection.

from df import DFGRPCClient, AuthenticationError

# Requires installing extra dependencies: pip install dataflare-sdk[grpc]
try:
    with DFGRPCClient() as client:
        # Perform unary RPC instead of REST natively
        results, next_cursor = client.datasets.query(
            dataset="legal", 
            limit=10,
        )
        
        for doc in results:
            print(f"Title: {getattr(doc, 'title', None)} | Summary: {getattr(doc, 'summary', None)}")

except AuthenticationError:
    print("Invalid API Key.")

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

dataflare_sdk-0.1.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

dataflare_sdk-0.1.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file dataflare_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: dataflare_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dataflare_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d56bf7d0f4968f0d1eafd749d58de06f00816cdfed9e5300285e0cafd2c67e2d
MD5 ade7acdd7bd36fab778d4b574a302152
BLAKE2b-256 eaf39ea7ef85459b63ea8b4fd9d2469d532d9c83a9bafe071d679b1f28e5989a

See more details on using hashes here.

File details

Details for the file dataflare_sdk-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: dataflare_sdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dataflare_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f8d57c78cf5f051b635d77da9be698c75c7a6ffb5f933b0c9bcc427426f669ee
MD5 6175d824193817e509affcdd7098b370
BLAKE2b-256 1ce76b4144cfbe92712b7287de25ab63cda3c35d6bc2d0dce4fe91f3526dc0a5

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