Skip to main content

A Python library for interacting with SageMaker deployments of the Isaacus API.

Project description

Isaacus SageMaker Python integration

The Isaacus SageMaker Python integration enables users to interact with private SageMaker deployments of Isaacus legal AI models via the Isaacus Python SDK.

This integration only requires a single line of code to be added to existing Isaacus API-based applications.

If you're looking for our AWS Marketplace listings, you can find them here. Additionally, we offer a complete guide on how to deploy and use Isaacus models on SageMaker on our docs.

Installation 📦

This integration can be installed with pip:

pip install isaacus-sagemaker

It also requires the isaacus package to be of any use:

pip install isaacus

Usage 👩‍💻

To use the Isaacus SageMaker integration, import either IsaacusSageMakerRuntimeHTTPClient (for synchronous usage) or AsyncIsaacusSageMakerRuntimeHTTPClient (for asynchronous usage) from isaacus_sagemaker along with IsaacusSageMakerRuntimeEndpoint to define available SageMaker endpoints.

Then, create an instance of the Isaacus or AsyncIsaacus client as you normally would, but also pass your SageMaker HTTP client as the http_client parameter.

Below is an example of how you'd do that in practice:

from isaacus import Isaacus, AsyncIsaacus
from isaacus_sagemaker import IsaacusSageMakerRuntimeHTTPClient, AsyncIsaacusSageMakerRuntimeHTTPClient, \
     IsaacusSageMakerRuntimeEndpoint

endpoints = [
    IsaacusSageMakerRuntimeEndpoint(
        name="my-sagemaker-endpoint",
        # region="us-west-2", # Optional, defaults to the client or AWS SDK default region
        # profile="my-aws-profile", # Optional, defaults to the client or AWS SDK default profile
        # models=["kanon-2-embedder"], # Optional, models supported by this endpoint,
        #                              # defaults to all models
    )
]

client = Isaacus(
    http_client=IsaacusSageMakerRuntimeHTTPClient(
        endpoints=endpoints,
        # region="us-west-2", # Optional, defaults to AWS SDK default region
        # profile="my-aws-profile", # Optional, defaults to AWS SDK default profile
        # boto_session_kwargs={"aws_access_key_id": "...",}, # Optional, additional boto3 session kwargs
        # **{}, # Optional, additional httpx.Client kwargs
    )
)

# For asynchronous usage:
aclient = AsyncIsaacus(
    http_client=AsyncIsaacusSageMakerRuntimeHTTPClient(
        endpoints=endpoints,
        # region="us-west-2", # Optional, defaults to AWS SDK default region
        # profile="my-aws-profile", # Optional, defaults to AWS SDK default profile
        # boto_session_kwargs={"aws_access_key_id": "...",}, # Optional, additional boto3 session kwargs
        # **{}, # Optional, additional httpx.AsyncClient kwargs
    )
)

Since Isaacus SageMaker deployments are private and hosted within your AWS account, no API key or base URL needs to be provided when constructing Isaacus SDK clients.

Once you've set up your client, no further changes are needed to your existing code.

API 🧩

IsaacusSageMakerRuntimeEndpoint

class IsaacusSageMakerRuntimeEndpoint(msgspec.Struct, frozen=True):
    name: str
    """The name of the SageMaker endpoint."""

    region: Optional[str] = None
    """The AWS region where the SageMaker endpoint is deployed. This overrides any region specified at the client-level."""

    profile: Optional[str] = None
    """The AWS profile to use when accessing the SageMaker endpoint. This overrides any profile specified at the client-level."""

    models: Optional[Sequence[str]] = None
    """The IDs of models served by this endpoint. If `None`, it is assumed the endpoint serves all models."""

IsaacusSageMakerRuntimeHTTPClient

class IsaacusSageMakerRuntimeHTTPClient(httpx.Client):
    """
    A synchronous Isaacus SDK-compatible HTTP client that proxies requests to SageMaker-deployed Isaacus models through the SageMaker Runtime InvokeEndpoint (`/invocations`) API.

    This client extends `httpx.Client`.

    Arguments:
        `endpoints` (`Sequence[IsaacusSageMakerRuntimeEndpoint] | IsaacusSageMakerRuntimeEndpoint`): A sequence of SageMaker endpoints to route requests to or a single endpoint.
        `region` (`str`, optional): The AWS region where the SageMaker endpoints are deployed. Overriden by any region specified at the endpoint-level. Defaults to `None`, in which case the AWS SDK's default region resolution is used.
        `profile` (`str`, optional): The AWS profile to use when accessing the SageMaker endpoints. Overriden by any profile specified at the endpoint-level. Defaults to `None`, in which case the AWS SDK's default profile resolution is used.
        `boto_session_kwargs` (`Dict[str, Any]`, optional): Additional keyword arguments to pass to the `boto3.Session` constructor when creating the AWS session. Defaults to `None`.
        `**httpx_kwargs` (`Any`): Additional keyword arguments to pass to the `httpx.Client` constructor.
    """

AsyncIsaacusSageMakerRuntimeHTTPClient

class AsyncIsaacusSageMakerRuntimeHTTPClient(httpx.AsyncClient):
    """
    An asynchronous Isaacus SDK-compatible HTTP client that proxies requests to SageMaker-deployed Isaacus models through the SageMaker Runtime InvokeEndpoint (`/invocations`) API.

    This client extends `httpx.AsyncClient`.

    Arguments:
        `endpoints` (`Sequence[IsaacusSageMakerRuntimeEndpoint] | IsaacusSageMakerRuntimeEndpoint`): A sequence of SageMaker endpoints to route requests to or a single endpoint.
        `region` (`str`, optional): The AWS region where the SageMaker endpoints are deployed. Overriden by any region specified at the endpoint-level. Defaults to `None`, in which case the AWS SDK's default region resolution is used.
        `profile` (`str`, optional): The AWS profile to use when accessing the SageMaker endpoints. Overriden by any profile specified at the endpoint-level. Defaults to `None`, in which case the AWS SDK's default profile resolution is used.
        `boto_session_kwargs` (`Dict[str, Any]`, optional): Additional keyword arguments to pass to the `boto3.Session` constructor when creating the AWS session. Defaults to `None`.
        `**httpx_kwargs` (`Any`): Additional keyword arguments to pass to the `httpx.Client` constructor.
    """

How it works ⚙️

This integration works by intercepting Isaacus SDK HTTP requests and proxying them to an Isaacus API server through the SageMaker Runtime InvokeEndpoint (/invocations) API.

When a request is made through the Isaacus SDK client, the custom HTTP client obtains the path, method, data, and headers from the original request and constructs a new request to the SageMaker endpoint's /invocations API that packages the original request details like so:

{
    "path": "/v1/embeddings",
    "method": "POST",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json"
    },
    "data": {
        "model": "kanon-2-embedder",
        "texts": ["This is a confidentiality clause."],
        "task": "retrieval/document"
    }
}

The Isaacus API server internally forwards the request to the appropriate internal endpoint and then SageMaker returns the response back to the custom HTTP client. If an error is encountered, SageMaker returns its own error response, which the custom HTTP client translates back into the original error, ensuring maximum compatibility with existing Isaacus SDK-based applications.

Changelog 🔄

All notable changes to this integration are documented in the CHANGELOG.md file. This project adheres to Keep a Changelog and Semantic Versioning.

License 📄

In the spirit of open source, this integration is licensed under the MIT License.

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

isaacus_sagemaker-0.1.4.tar.gz (102.8 kB view details)

Uploaded Source

Built Distribution

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

isaacus_sagemaker-0.1.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file isaacus_sagemaker-0.1.4.tar.gz.

File metadata

  • Download URL: isaacus_sagemaker-0.1.4.tar.gz
  • Upload date:
  • Size: 102.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for isaacus_sagemaker-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cd9bcae680e049e53a30c2967e3890b7bd6ccf7a3c4484ee87645fc7467d25bb
MD5 ac4fcf29399c59e776428486d74d334e
BLAKE2b-256 dfc38f3b8533709a27d7ae03811945ba148e78124b22008e34b63f2aa36bb5ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for isaacus_sagemaker-0.1.4.tar.gz:

Publisher: publish.yaml on isaacus-dev/isaacus-sagemaker-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file isaacus_sagemaker-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for isaacus_sagemaker-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f361d2e3cc6920c4c7d4420c273bf2bd42a2f8f0a57561fc634a0dc6004f29a0
MD5 0415efdc4f7db3bcb24879961e3be953
BLAKE2b-256 efcf8103e01551f1e7703945526ccdaddb7164430053a92aff749a1f3243ee42

See more details on using hashes here.

Provenance

The following attestation bundles were made for isaacus_sagemaker-0.1.4-py3-none-any.whl:

Publisher: publish.yaml on isaacus-dev/isaacus-sagemaker-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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