Metadata-Version: 2.4
Name: mirascope
Version: 2.0.2
Summary: Every frontier LLM. One unified interface.
Project-URL: Homepage, https://mirascope.com
Project-URL: Documentation, https://mirascope.com/docs/mirascope/v2
Project-URL: Repository, https://github.com/Mirascope/mirascope/tree/v2
Project-URL: Issues, https://github.com/Mirascope/mirascope/issues
Project-URL: Changelog, https://github.com/Mirascope/mirascope/releases
Author-email: William Bakst <william@mirascope.com>, Dandelion Mané <dandelion@mirascope.com>
Maintainer-email: William Bakst <william@mirascope.com>, Dandelion Mané <dandelion@mirascope.com>
License: MIT License
        
        Copyright (c) 2026 Mirascope, Inc.
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agents,anthropic,artificial intelligence,context engineering,developer tools,gemini,llm,llm tools,openai,prompt engineering
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: File Formats :: JSON
Classifier: Topic :: File Formats :: JSON :: JSON Schema
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: docstring-parser>=0.17.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: jiter>=0.7.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: typing-extensions>=4.10.0
Provides-Extra: all
Requires-Dist: anthropic<1.0,>=0.76.0; extra == 'all'
Requires-Dist: google-genai<2,>=1.58.0; extra == 'all'
Requires-Dist: libcst>=1.8.6; extra == 'all'
Requires-Dist: mcp<2,>=1.25.0; extra == 'all'
Requires-Dist: mlx-lm<1,>=0.28.4; extra == 'all'
Requires-Dist: openai<3,>=2.15.0; extra == 'all'
Requires-Dist: opentelemetry-api<2,>=1.38.0; extra == 'all'
Requires-Dist: opentelemetry-exporter-otlp<2,>=1.38.0; extra == 'all'
Requires-Dist: opentelemetry-instrumentation<1,>=0.59b0; extra == 'all'
Requires-Dist: opentelemetry-propagator-b3<2,>=1.38.0; extra == 'all'
Requires-Dist: opentelemetry-propagator-b3>=1.38.0; extra == 'all'
Requires-Dist: opentelemetry-propagator-jaeger>=1.38.0; extra == 'all'
Requires-Dist: opentelemetry-sdk<2,>=1.38.0; extra == 'all'
Requires-Dist: orjson>=3.11.4; extra == 'all'
Requires-Dist: packaging>=25.0; extra == 'all'
Requires-Dist: pillow<11,>=10.4.0; extra == 'all'
Requires-Dist: proto-plus>=1.24.0; extra == 'all'
Requires-Dist: pydantic-settings>=2.12.0; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic<1.0,>=0.76.0; extra == 'anthropic'
Provides-Extra: api
Requires-Dist: pydantic-settings>=2.12.0; extra == 'api'
Provides-Extra: google
Requires-Dist: google-genai<2,>=1.58.0; extra == 'google'
Requires-Dist: pillow<11,>=10.4.0; extra == 'google'
Requires-Dist: proto-plus>=1.24.0; extra == 'google'
Provides-Extra: mcp
Requires-Dist: mcp<2,>=1.25.0; extra == 'mcp'
Provides-Extra: mlx
Requires-Dist: mlx-lm<1,>=0.28.4; extra == 'mlx'
Provides-Extra: openai
Requires-Dist: openai<3,>=2.15.0; extra == 'openai'
Provides-Extra: ops
Requires-Dist: libcst>=1.8.6; extra == 'ops'
Requires-Dist: opentelemetry-api<2,>=1.38.0; extra == 'ops'
Requires-Dist: opentelemetry-exporter-otlp<2,>=1.38.0; extra == 'ops'
Requires-Dist: opentelemetry-instrumentation<1,>=0.59b0; extra == 'ops'
Requires-Dist: opentelemetry-propagator-b3<2,>=1.38.0; extra == 'ops'
Requires-Dist: opentelemetry-propagator-b3>=1.38.0; extra == 'ops'
Requires-Dist: opentelemetry-propagator-jaeger>=1.38.0; extra == 'ops'
Requires-Dist: opentelemetry-sdk<2,>=1.38.0; extra == 'ops'
Requires-Dist: orjson>=3.11.4; extra == 'ops'
Requires-Dist: packaging>=25.0; extra == 'ops'
Description-Content-Type: text/markdown

## Mirascope v2 Python

This directory contains the Python implementation of Mirascope.

## Development Setup

1. **Environment Variables**: Copy `.env.example` to `.env` and fill in your API keys:
   ```bash
   cp .env.example .env
   # Edit .env with your API keys
   ```

2. **Install Dependencies**:

   ```bash
   uv sync --all-extras --dev
   ```

3. **Run Tests**:
   ```bash
   uv run pytest
   ```

## `ops.span` and Session Tracing

`mirascope.ops` provides tracing helpers to trace any Python function, not just
`llm.Model` calls.

1. Install the OTEL extra and set up a tracer provider exactly as shown above.
   `ops.span` automatically reuses the active provider, so spans from manual
   instrumentation and GenAI instrumentation end up in the same trace tree.
2. Use `ops.session` to group related spans and attach metadata:
   ```python
   from mirascope import ops

   with ops.session(id="req-42", attributes={"team": "core"}):
       with ops.span("load-data") as span:
           span.set(stage="ingest")
           # expensive work here
   ```
3. The span exposes `span_id`/`trace_id`, logging helpers, and graceful no-op
   behavior when OTEL is not configured. When OTEL is active, session metadata is
   attached to every span, and additional tools like `ops.trace`/`ops.version`
   (planned) can build on the same context.

## `ops.trace` Decorator

`@ops.trace` adds span instrumentation to any Python callable (including
`llm.Model` helpers) so you can capture argument/return metadata alongside the
GenAI spans emitted by `llm.instrument_opentelemetry`.

```python
from mirascope import ops

@ops.trace(tags=["ingest"])
def normalize(record: dict[str, str]) -> dict[str, str]:
    return {k: v.strip() for k, v in record.items()}

result = normalize({"foo": " bar "})
wrapped = normalize.wrapped({"foo": " bar "})
print(wrapped.span_id, wrapped.trace_id)
```

- The decorator automatically handles sync/async functions and reuses `ops.span`
  serialization logic for arguments/results.
- Combine with `ops.session` to tag spans with contextual metadata, and with
  `ops.instrument_opentelemetry` to obtain both model-level GenAI spans
  and method-level spans like `recommend_book.__call__`.
- For now we focus on Mirascope-layer entry points (e.g., decorated functions or
  `llm.Model` wrappers) and do not auto-instrument underlying provider SDK calls.

## Testing

### VCR Cassettes

The project uses [VCR.py](https://vcrpy.readthedocs.io/) to record and replay HTTP interactions with LLM APIs. This allows tests to run quickly and consistently without making actual API calls.

- **Cassettes Location**: Test cassettes are stored in `tests/llm/clients/*/cassettes/`
- **Recording Mode**: Tests use `"once"` mode - records new interactions if no cassette exists, replays existing cassettes otherwise
- **CI/CD**: In CI environments, tests use existing cassettes and never make real API calls

### Inline Snapshots

The project uses [inline-snapshot](https://15r10nk.github.io/inline-snapshot/) to capture expected test outputs directly in the test code.

- **Update Snapshots**: Run `uv run pytest --inline-snapshot=fix` to update all snapshots with actual values
- **Review Changes**: Run `uv run pytest --inline-snapshot=review` to preview what would change
- **Formatted Output**: Snapshots are automatically formatted with `ruff` for consistency

Example:
```python
def test_api_response():
    response = client.call(messages=[user("Hello")])
    assert response.content == snapshot([Text(text="Hi there!")])
```

### Recording New Test Interactions

To record new test interactions:

1. Ensure your API keys are set in `.env`
2. Delete the relevant cassette file (if updating an existing test)
3. Run the specific test: `uv run pytest tests/path/to/test.py::test_name`
4. The cassette will be automatically created/updated
