Skip to main content

Python client for Rabbit BigQuery Job Optimizer API

Project description

Rabbit BigQuery Job Optimizer Python Client

This is the official Python client library for the Rabbit BigQuery Job Optimizer API.

Installation

pip install rabbit-bq-job-optimizer

Usage

from rabbit_bq_job_optimizer import RabbitBQOptimizer, OptimizationConfig

# Initialize the client
client = RabbitBQOptimizer(
    api_key="your-api-key",
    base_url="https://api.rabbit.com/v1"  
)

# Optimize a BigQuery job configuration
job_config = {
    "configuration": {
        "query": {
            "query": "SELECT * FROM my_table",
            "useLegacySql": False,
            "priority": "INTERACTIVE"
        }
    }
}

optimization_config = OptimizationConfig(
    type="reservation_assignment",
    config={
        "defaultPricingMode": "on_demand",
        "reservationIds": [
            "my-project:US.my-reservation-us",
            "my-project:EU.my-reservation-eu"
        ]
    }
)

# Optimize the job
result = client.optimize_job(
    configuration=job_config,
    enabledOptimizations=[optimization_config]
)

# Access the optimized configuration
optimized_config = result.optimizedJob

# Access optimization results
for optimization in result.optimizationResults:
    print(f"Type: {optimization.type}")
    print(f"Applied: {optimization.performed}")
    print(f"Estimated Savings: {optimization.estimatedSavings}")

Error Handling

The client raises exceptions for API errors:

from rabbit_bq_job_optimizer import RabbitBQOptimizerError

try:
    result = client.optimize_job(job_config)
except RabbitBQOptimizerError as e:
    print(f"Error: {e.message}")
    print(f"Status Code: {e.status_code}")

Authentication

The API key and base URL are required to use the client. These can be obtained from the Rabbit team by contacting success@followrabbit.ai.

There are two ways to configure authentication:

  1. Pass directly to the constructor:
from rabbit_bq_job_optimizer import RabbitBQOptimizer

client = RabbitBQOptimizer(
    api_key="your-api-key",
    base_url="your-base-url"
)
  1. Set environment variables:
export RABBIT_API_KEY="your-api-key"
export RABBIT_API_BASE_URL="your-base-url"

Then initialize the client without parameters:

from rabbit_bq_job_optimizer import RabbitBQOptimizer

client = RabbitBQOptimizer()  # Will automatically use environment variables

The environment variables are:

  • RABBIT_API_KEY: Your Rabbit API key
  • RABBIT_API_BASE_URL: The base URL for the Rabbit API

Development

To install the package in development mode:

pip install -e .

License

Apache License 2.0

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

rabbit_bq_job_optimizer-0.1.6.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

rabbit_bq_job_optimizer-0.1.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file rabbit_bq_job_optimizer-0.1.6.tar.gz.

File metadata

  • Download URL: rabbit_bq_job_optimizer-0.1.6.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for rabbit_bq_job_optimizer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 20da9dfe74c54d91aae78f495bd6f98be6f08d9606423a177f6e44302717bd64
MD5 ce9f6e93f2d668d567169334c11a00e4
BLAKE2b-256 1c8ed699f8a6216a00941e803e2b50267c095d9f35c40692eae9f4c18597b675

See more details on using hashes here.

File details

Details for the file rabbit_bq_job_optimizer-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for rabbit_bq_job_optimizer-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 27378a45d7a38772598084093e3797862c3f103310a226f67f5e5797700ef0ec
MD5 f693c3cd60472354660e4f6d5bef0604
BLAKE2b-256 d88dadef91fe41b5f288b2f51fc52ff2c031d11aa1d917e5ed2ab5c72d3ad515

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