Metadata-Version: 2.5
Name: magentic-datacircle
Version: 0.1.0
Summary: magentic functions for the Datacircle API: find the best GTM APIs
Project-URL: Homepage, https://datacircle.dev
Project-URL: Documentation, https://api.datacircle.dev/v1/openapi.json
Project-URL: Repository, https://github.com/waynehamadi/magentic-datacircle
License-Expression: MIT
License-File: LICENSE
Keywords: api,api-pricing,b2b-data,datacircle,function-calling,gtm,llm,magentic,prompt-chain,tools
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: pydantic>=2.10
Description-Content-Type: text/markdown

# magentic-datacircle

Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website.

Our website: https://datacircle.dev

This package gives [magentic](https://github.com/jackmpcollins/magentic) four functions that call Datacircle's open API, https://api.datacircle.dev/v1. You need no key and no account. Each function has type hints and a docstring. Each argument has a description. magentic reads the name, docstring and arguments of each function. magentic sends the name, docstring and arguments to the model.

| Function | What the function gives | Call |
| --- | --- | --- |
| `datacircle_list_apis` | Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan | `GET /apis` |
| `datacircle_best_plans` | One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls | `GET /apis/{slug}/best` |
| `datacircle_search_plans` | Plans that match a provider or plan name, on all APIs or on one API. You can sort them by score, provider or price | `GET /plans` |
| `datacircle_provider` | The APIs a provider sells, and the provider's rank on each API | `GET /providers/{slug}` |

## Install

```bash
pip install magentic-datacircle magentic
```

magentic-datacircle works with magentic 0.40 and later, on Python 3.10 and later. magentic-datacircle does not import `magentic`.

magentic uses OpenAI's `gpt-4o` by default. To use another model for each prompt, set `MAGENTIC_OPENAI_MODEL`. To use another model for one prompt, pass `model=` to that prompt. The Datacircle functions work with each of magentic's chat models: `OpenaiChatModel`, `AnthropicChatModel` and `LitellmChatModel`.

## Use the functions in a prompt chain

With `@prompt_chain`, magentic runs each function call from the model. magentic then gives each function result back to the model. magentic repeats these steps until the model has the final answer:

```python
from magentic import prompt_chain
from magentic_datacircle import datacircle_functions


@prompt_chain("Who are the 3 best providers for the {api} API? Name each with its score.", functions=datacircle_functions())
def best_providers(api: str) -> str: ...


print(best_providers("email-finder"))
```

## Call the function yourself

With `@prompt`, the model returns a `FunctionCall`. You choose when to call the `FunctionCall`:

```python
from magentic import FunctionCall, prompt
from magentic_datacircle import datacircle_functions


@prompt("Find the best plans for the {api} API.", functions=datacircle_functions())
def plan(api: str) -> FunctionCall[str]: ...


call = plan("email-finder")
print(call())
```

To get many calls at once, set the return type to `ParallelFunctionCall[str]`.

## Use the Datacircle functions in a chat prompt

`@chatprompt` takes `functions=datacircle_functions()`:

```python
from magentic import FunctionCall, SystemMessage, UserMessage, chatprompt
from magentic_datacircle import datacircle_functions


@chatprompt(
    SystemMessage("Use the Datacircle functions for questions on GTM APIs."),
    UserMessage("On which APIs does {provider} rank?"),
    functions=datacircle_functions(),
)
def ranks(provider: str) -> FunctionCall[str]: ...


print(ranks("Hunter")())
```

## Use the functions in async code

For a prompt on an `async def`, use `datacircle_async_functions()`. The async functions have the same names and arguments as the sync functions. Each async function runs the API call in a thread. Several calls then run at the same time:

```python
import asyncio

from magentic import prompt_chain
from magentic_datacircle import datacircle_async_functions


@prompt_chain("Who is the best provider for the {api} API?", functions=datacircle_async_functions())
async def best_provider(api: str) -> str: ...


print(asyncio.run(best_provider("email-finder")))
```

## Use the Datacircle functions beside your own functions

Put the Datacircle functions in one list with your own functions: `functions=[*datacircle_functions(), my_function]`.

To give the model only some Datacircle functions, list the names of those functions: `datacircle_functions(["datacircle_best_plans"])`.

## Call a function without a model

Each function runs without a model. You get the Datacircle API's answer as JSON text:

```python
import json

from magentic_datacircle import datacircle_best_plans, run

print(json.loads(datacircle_best_plans("email-finder", limit=3))["plans"])
print(run("datacircle_provider", {"slug": "Bright Data"}))
```

## What the model reads

Each function returns the API's answer as JSON text. magentic gives the model this text with every backend. Each plan comes with a rank, provider, plan, score, price per 1,000 (`perThousand`, in dollars) and a page on datacircle.dev. That page lists every field.

You can give a provider's name in place of a slug. The function turns `Bright Data` into `bright-data`.

An unknown slug gets no data from the API. With no data, the function returns `{"error": "..."}` and the API's message. The error for an unknown API slug lists every valid slug. The function checks each number from the model before any API call. For a number out of range, the function returns `{"error": "..."}` and makes no API call. If the network fails, the function returns `{"error": "..."}` with the network error's message. The function never raises an error. Your prompt chain keeps running. The model can call the function again.

## Network

Each function call makes one HTTPS GET request to https://api.datacircle.dev/v1 and nothing else. The request holds only the function's own arguments: no key and nothing from your prompts. The API takes up to 60 calls a minute from one IP address. The API can ask the function to wait. The function then waits once, for a minute at most. Each call uses only Python's standard library. Nothing goes to disk.

## Links

- Datacircle: https://datacircle.dev
- The API's spec: https://api.datacircle.dev/v1/openapi.json
