Metadata-Version: 2.5
Name: openai-datacircle
Version: 0.1.0
Summary: Tools for the OpenAI Python library on 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/openai-python-datacircle
License-Expression: MIT
License-File: LICENSE
Keywords: api,api-pricing,b2b-data,datacircle,function-calling,gtm,llm,openai,responses,tool-calling,tools
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Requires-Dist: openai>=1.66.0
Description-Content-Type: text/markdown

# openai-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 the [OpenAI Python library](https://github.com/openai/openai-python) four tools that call Datacircle's open API, https://api.datacircle.dev/v1. You pass the four Datacircle tools to `client.chat.completions` or `client.responses`. The package then runs each tool call the model returns. Our API needs no key and no account.

| Tool | What the tool 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 openai-datacircle
```

openai-datacircle works with `openai` 1.66.0 and later, on Python 3.9 and later.

## Use the tools with Chat Completions

Pass the tools to `client.chat.completions.create()`. If the model calls a tool, `call_all()` gives you the tool messages to send back:

```python
from openai import OpenAI
from openai_datacircle import call_all, datacircle_tools

client = OpenAI()
messages = [{"role": "user", "content": "Who are the 3 best providers for the email-finder API?"}]
message = client.chat.completions.create(model="gpt-5.4-mini", messages=messages, tools=datacircle_tools()).choices[0].message

while message.tool_calls:
    messages.append(message)
    messages.extend(call_all(message))
    message = client.chat.completions.create(model="gpt-5.4-mini", messages=messages, tools=datacircle_tools()).choices[0].message

print(message.content)
```

Each tool message has `role: "tool"`, the call's id in `tool_call_id`, and the answer as JSON text in `content`.

`client.chat.completions.parse()` takes only strict tools. Use `datacircle_tools(strict=True)` with `parse()`. In strict mode the model gives every argument. For an optional argument, the model can send `null`. The Datacircle tools treat `null` as a missing argument.

With `client.chat.completions.stream()`, pass the message of `stream.get_final_completion()` to `call_all()`. Before `openai` 1.92.0, `parse()` and `stream()` are in `client.beta.chat.completions`.

With `AsyncOpenAI`, use `await acall_all(message)`. `acall_all()` runs the calls at the same time. Your event loop keeps running.

## Use the tools with the Responses API

`responses_tools()` gives the four Datacircle tools in the Responses API's format. `call_outputs()` gives the `function_call_output` items to send back:

```python
from openai import OpenAI
from openai_datacircle import call_outputs, responses_tools

client = OpenAI()
given = [{"role": "user", "content": "Who are the 3 best providers for the email-finder API?"}]
response = client.responses.create(model="gpt-5.4-mini", input=given, tools=responses_tools())

while any(item.type == "function_call" for item in response.output):
    given += response.output
    given += call_outputs(response)
    response = client.responses.create(model="gpt-5.4-mini", input=given, tools=responses_tools())

print(response.output_text)
```

`call_outputs()` also works with `client.responses.parse()`. `call_outputs()` also works with `client.responses.stream()` and the stream's `get_final_response()`. With `AsyncOpenAI`, use `await acall_outputs(response)`.

The Responses API treats a tool with no `strict` field as strict. `responses_tools()` sets `strict` on each tool. By default, `strict` is `False`. `responses_tools(strict=True)` sets `strict` to `True`.

## Use the tools with ResponsesToolRunner

`openai` 3.31.0 and later can run the whole tool loop with `ResponsesToolRunner`. `registered_functions()` gives the four Datacircle tools as a list of `RegisteredFunction` objects:

```python
from openai import OpenAI
from openai.lib.responses_tool_runner import ResponsesToolRunner
from openai_datacircle import registered_functions

runner = ResponsesToolRunner(functions=registered_functions())
response = runner.run(
    OpenAI(),
    {"model": "gpt-5.4-mini", "input": "Who are the 3 best providers for the email-finder API?"},
    max_steps=6,
)
print(response.output_text)
```

With `AsyncResponsesToolRunner`, use `async_registered_functions()`. The runner stops at a call to an unknown tool. Give the runner each of your own tools as a `RegisteredFunction` too: `functions=[*registered_functions(), my_function]`.

## Use the Datacircle tools beside your own tools

You can put the Datacircle tools in the same list as yours: `tools=[*datacircle_tools(), my_tool]`.

`call()` runs one tool call. For your own tools, `call()` returns `None`. Your code then runs the tool itself:

```python
from openai_datacircle import call

for tool_call in message.tool_calls or []:
    messages.append(call(tool_call) or my_tool_message(tool_call))
```

`call_output()` runs one tool call from one item of a Responses API answer. To give the model fewer Datacircle tools, list the tool names: `datacircle_tools(["datacircle_best_plans"])`.

## Use the tools on another server

The tools work with any server that offers OpenAI's API. Give the server's address to the client: `OpenAI(base_url="https://.../v1", api_key="...")`.

## Call a tool yourself

You can call each tool without a model. You get the JSON text of the tool's answer:

```python
import json

from openai_datacircle import run

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

## What the model reads

Each tool gives the model a JSON object as text. 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 tool turns `Bright Data` into `bright-data`.

The tool returns `{"error": "..."}` with the API's message when the API gives no data, such as for an unknown slug. The error for an unknown API slug lists every valid slug. The tool checks each number from the model first. For a number out of range, the tool returns `{"error": "..."}` and makes no API call. If the network fails, the tool returns `{"error": "..."}` with the network error's message. The model can then call the tool again.

## Network

Each tool call makes one HTTPS GET request to https://api.datacircle.dev/v1 and nothing else. The request holds only the tool's own arguments: no key and nothing from your chats. The API takes up to 60 calls a minute from one IP address. The API can ask the tool to wait. The tool 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: https://datacircle.dev/api
- The API's spec: https://api.datacircle.dev/v1/openapi.json
- Every field of a plan: https://datacircle.dev/fields

MIT license.
