Skip to main content

Astrux Python SDK

PyPI version Python versions License: MIT

The official Python SDK for interacting with the Astrux API. Make machine learning predictions in just a few lines of code.

Installation

pip install astrux

Quick Start

from astrux import Astrux

# Initialize the client
client = Astrux(api_key="sk_your_api_key")

# Make a prediction
result = client.models.predict(
    model="my-model",
    input={"feature1": 10, "feature2": 20}
)

print(result["score"])  # Prediction score

Configuration

API Key

You can provide your API key in two ways:

1. As a parameter (recommended):

client = Astrux(api_key="sk_your_api_key")

2. Via environment variable:

export ASTRUX_API_KEY=sk_your_api_key
client = Astrux()  # Automatically loads from ASTRUX_API_KEY

Custom Timeout

The default timeout is 30 seconds. You can customize it:

client = Astrux(api_key="sk_your_api_key", timeout=60.0)

Usage

Simple Prediction

from astrux import Astrux

client = Astrux(api_key="sk_your_api_key")

# Regression
result = client.models.predict(
    model="house-prices",
    input={
        "sqft": 120,
        "bedrooms": 3,
        "city": "Paris"
    }
)
print(f"Estimated price: {result['score']}")

Prediction with Specific Version

# Use a specific model version
result = client.models.predict(
    model="sentiment-analysis",
    input={"text": "This product is excellent!"},
    version=2
)

Classification

For classification tasks, the response includes the predicted class and probabilities:

result = client.models.predict(
    model="image-classification",
    input={"image_url": "https://example.com/image.jpg"}
)

print(f"Class: {result['class_']}")  # Predicted class
print(f"Probabilities: {result['proba']}")  # List of probabilities

Model Metadata

The response may include metadata about the model used:

result = client.models.predict(
    model="my-model",
    input={"feature": 42}
)

print(f"Model ID: {result.get('model_id')}")
print(f"Model name: {result.get('model_name')}")
print(f"Version: {result.get('version')}")
print(f"Task type: {result.get('task_type')}")

Error Handling

The SDK provides specific exceptions for different error types:

from astrux import Astrux
from astrux._errors import (
    AuthenticationError,
    NotFoundError,
    ValidationError,
    RateLimitError,
    ServerError,
    AstruxError
)

client = Astrux(api_key="sk_your_api_key")

try:
    result = client.models.predict(
        model="my-model",
        input={"feature": "value"}
    )
except AuthenticationError as e:
    print(f"Authentication error: {e}")
except NotFoundError as e:
    print(f"Model not found: {e}")
except ValidationError as e:
    print(f"Invalid data: {e}")
    print(f"Details: {e.payload}")
except RateLimitError as e:
    print(f"Rate limit exceeded: {e}")
except ServerError as e:
    print(f"Server error: {e}")
except AstruxError as e:
    print(f"Astrux error: {e}")
    print(f"Status code: {e.status}")

Closing the Client

To release resources, close the client after use:

client = Astrux(api_key="sk_your_api_key")

try:
    result = client.models.predict(model="my-model", input={"x": 1})
    print(result)
finally:
    client.close()

Response Structure

Regression

{
    "score": 42.5,
    "model_id": "abc123",
    "model_name": "my-model",
    "version": 1,
    "task_type": "regression"
}

Classification

{
    "score": 0.95,
    "class_": "positive",  # Note: remapped from "class"
    "proba": [0.05, 0.95],
    "model_id": "def456",
    "model_name": "sentiment",
    "version": 2,
    "task_type": "classification"
}

Requirements

  • Python >= 3.8
  • httpx >= 0.27.0

License

MIT - see LICENSE file for details.

Author

Thomas Bodénan - thomas.bodenan@gmail.com

Support

For questions or issues, consult the official documentation or contact Astrux support.

Metadata

Release files for astrux 0.1.2

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

Source distribution (sdist)

Source distribution for astrux 0.1.2
File Size Uploaded
astrux-0.1.2.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for astrux 0.1.2
File Interpreter ABI Platform
astrux-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / astrux-0.1.2.tar.gz

Download URL astrux-0.1.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2abc5a02095e930d94850610cd22362428d4d64846b6f02c223521251bee58bb
BLAKE2b-256 checksum
How to use checksums
eb7e9297dc510a631898289139bfa8255860e33831f6f51d5659cf73262a2e2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / astrux-0.1.2-py3-none-any.whl

Download URL astrux-0.1.2-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feec8c4b93be2383d16fe7465466924606793feb78f2d14bc4351ceb83e9780b
BLAKE2b-256 checksum
How to use checksums
32ad465e7d20a121c537402e72bd512526381c049553186ac00cdb440be1c078
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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