Skip to main content

Mirascope Python

This directory contains the Python implementation of Mirascope: The LLM Anti-Framework. It's intended as a "Goldilocks API" that affords the fine-grained control you'd get from using raw provider APIs, as well as the type safety and easy ergonomics that are offered by higher-level agent frameworks. Think of Mirascope as the "React" of LLM development, where provider native APIs are HTML/CSS, and the agent frameworks are Angular.

Documentation

Installation

# using uv, with all provider deps
uv add "mirascope[all]"

# using uv, with just Anthropic
uv add "mirascope[anthropic]"

# using pip, with all deps 
pip install "mirascope[all]"

# using pip, just OpenAI
pip install "mirascope[openai]"

Usage

Here's an example of creating a simple agent, with tool-calling and streaming, using Mirascope. For many more examples, read the docs.

from mirascope import llm

@llm.tool
def exp(a: float, b: float) -> float:
   """Compute an exponent"""
   return a ** b

@llm.tool
def add(a: float, b: float) -> float:
   """Add two numbers"""
   return a + b

model = llm.Model("anthropic/claude-haiku-4-5")
response = model.stream("What is 42 ** 4 + 37 ** 3?", tools=[exp, add])

while True:
   for stream in response.streams():
         if stream.content_type == "text":
            for delta in stream:
               print(delta, end="", flush=True)
         elif stream.content_type == "tool_call":
            stream.collect()  # consume the stream
            print(f"\n> Calling {stream.tool_name}({stream.partial_args})")
   print()
   if response.tool_calls:
         response = response.resume(response.execute_tools())
   else:
         break

Development Setup

  1. Environment Variables: Copy .env.example to .env and fill in your API keys:

    cp .env.example .env
    # Edit .env with your API keys
    # Necessary for updating e2e snapshot tests
    
  2. Install Dependencies:

    cd python
    uv sync --all-extras --dev
    

Helpful Commands:

Here are helpful development commands. All must be run from within the python directory.

  • uv run pyright .

Run typechecking.

  • uv run ruff check --fix .

Check ruff linter (fixing issues where possible).

  • uv run ruff format .

Run ruff formatter.

  • uv run pytest

Run all Python unit tests.

  • uv run pytest --cov --cov-config=.coverargc --cov-report=term-missing

Run all Python unit tests, and report code coverage. (We require 100% coverage in CI.)

  • uv run pytest --fix

Run all Python unit tests, and update any changed snapshots.

  • uvx codespell --config ../.codespellrc

Run codespell, identifying many common spelling mistakes.

Typechecking

We prize type safety, both on the API surface and internally. You can run typechecking via uv run pyright . within this python/ directory. (We're looking into supporting ty so as to speed up our typechecking.)

Testing

This project makes extensive use of e2e tests, which replay real interactions with various LLM providers to ensure that Mirascope truly works on the providers' APIs. We use VCR.py and inline-snapshot to maintain these e2e tests. For more details, read tests/e2e/README.md.

If you make changes to Mirascope that require new snapshots, you should manually delete the outdated cassette files, and then run uv run pytest python/tests/e2e --fix. Note that doing so requires real API keys in your .env file.

We require 100% code coverage in CI. You can get a code coverage report via:

uv run pytest --cov --cov-config=.coverargc --cov-report=term-missing

Read More

For more info on contributing, read the contributing page in our docs.

Metadata

Release files for mirascope 2.8.0

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

Source distribution (sdist)

Source distribution for mirascope 2.8.0
File Size Uploaded Provenance
mirascope-2.8.0.tar.gz 22.6 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 22.9 MB

Release files / mirascope-2.8.0.tar.gz

Download URL mirascope-2.8.0.tar.gz
Size 22.6 MB
Tags Source
SHA-256 checksum
How to use checksums
bfc5af0c23242e65aac71ddff2dda662da7f95f4c6056ce2caaa12e0d94554e9
BLAKE2b-256 checksum
How to use checksums
6e5b8bacf294a762eaccbcaac86510db7f869499c08a255207ce8f3944c3065b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mirascope-2.8.0-py3-none-any.whl

Download URL mirascope-2.8.0-py3-none-any.whl
Size 287.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3f9aa3e3fd64515e3baae2c33fcf9c8c604103c6ec011cd117238114533f4a2
BLAKE2b-256 checksum
How to use checksums
15c67d4cf13cd6d57e38b5ca6a022a84d435818556fa3bf360eca2f5652922a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for mirascope 2.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

2.8.0 This release

2 release files No provenance

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