Skip to main content

Dagster integration with Anthropic

Project description

dagster-anthropic

A dagster module that provides integration with Anthropic.

Installation

The dagster_anthropic module is available as a PyPI package - install with your preferred python environment manager (We recommend uv).

source .venv/bin/activate
uv pip install dagster_anthropic

Example Usage

In addition to wrapping the Anthropic client (get_client/get_client_for_asset methods), this resource logs the usage of the Anthropic API to to the asset metadata (both number of calls, and tokens). This is achieved by wrapping the Anthropic.messages.create method.

Note that the usage will only be logged to the asset metadata from an Asset context - not from an Op context. Also note that only the synchronous API usage metadata will be automatically logged - not the streaming or batching API.

from dagster import AssetExecutionContext, Definitions, EnvVar, asset, define_asset_job
from dagster_anthropic import AnthropicResource


@asset(compute_kind="anthropic")
def anthropic_asset(context: AssetExecutionContext, anthropic: AnthropicResource):
    with anthropic.get_client(context) as client:
        response = client.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=1024,
            messages=[
                {"role": "user", "content": "Say this is a test"}
            ]
        )

defs = Definitions(
    assets=[anthropic_asset],
    resources={
        "anthropic": AnthropicResource(api_key=EnvVar("ANTHROPIC_API_KEY")),
    },
)

Development

The Makefile provides the tools required to test and lint your local installation

make test
make ruff
make check

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

dagster_anthropic-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

dagster_anthropic-0.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file dagster_anthropic-0.0.1.tar.gz.

File metadata

  • Download URL: dagster_anthropic-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for dagster_anthropic-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3eee29a191f634f00de64024f0f0012749b28404be25f17c1d9094852d3f6bef
MD5 883d277f78be45b88fdb49ad06bf07f1
BLAKE2b-256 41ab653f54ced7e2d0d737e1ce4abdafb62cb5479189691ccf7f5ee575f4c4ba

See more details on using hashes here.

File details

Details for the file dagster_anthropic-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dagster_anthropic-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c27e86209b5e4b52aeb5c7ea49ecc1c112e56d7a3d5b7fef8eb4c93b003de81b
MD5 e4ba904dd2084fbc4d402ca6c4eb4ae1
BLAKE2b-256 0a0f13a2773feb125bfd756b131818fb834782ff81c9e9628f3ea279dfa89bd8

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