Metadata-Version: 2.5
Name: huggingface-hub-datacircle
Version: 0.1.0
Summary: Hugging Face InferenceClient tools 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/huggingface-hub-datacircle
License-Expression: MIT
License-File: LICENSE
Keywords: api,api-pricing,b2b-data,datacircle,function-calling,gtm,huggingface,huggingface-hub,inference,tool-calling,tools
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Requires-Dist: huggingface-hub>=0.24.6
Description-Content-Type: text/markdown

# huggingface-hub-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 `InferenceClient` of [huggingface_hub](https://github.com/huggingface/huggingface_hub) four tools that call Datacircle's open API, https://api.datacircle.dev/v1. You pass the tools to `client.chat_completion()`. The package then runs each tool call from the model. You can run the tools on Inference Providers or on your own server. You need no key and no account for Datacircle.

| 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 huggingface-hub-datacircle
```

huggingface-hub-datacircle works with `huggingface_hub` 0.24.6 and later, on Python 3.9 and later.

## Use the tools

Send the tools with `client.chat_completion()`. If the model calls a tool, `call_all()` gives you the tool messages to send back:

```python
from huggingface_hub import InferenceClient
from huggingface_hub_datacircle import call_all, datacircle_tools

client = InferenceClient()
model = "Qwen/Qwen3-235B-A22B-Instruct-2507"
messages = [{"role": "user", "content": "Who are the 3 best providers for the email-finder API?"}]
response = client.chat_completion(messages, model=model, tools=datacircle_tools())

while response.choices[0].message.tool_calls:
    messages.append(response.choices[0].message)
    messages.extend(call_all(response.choices[0].message))
    response = client.chat_completion(messages, model=model, tools=datacircle_tools())

print(response.choices[0].message.content)
```

`InferenceClient()` reads your Hugging Face token from `HF_TOKEN` or from `hf auth login`. For your own server, use `InferenceClient(base_url="http://localhost:8080/v1")`. `client.chat.completions.create()` takes the same arguments as `client.chat_completion()`.

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

## Stream

With `stream=True`, some chunks hold pieces of tool calls. Pass each chunk's `delta.tool_calls` to `collect_tool_calls()`. `collect_tool_calls()` puts the pieces of each call together in one list. Then run the list with `call_all()`:

```python
from huggingface_hub import InferenceClient
from huggingface_hub_datacircle import call_all, collect_tool_calls, datacircle_tools

client = InferenceClient()
model = "Qwen/Qwen3-235B-A22B-Instruct-2507"
messages = [{"role": "user", "content": "Which APIs does the provider Bright Data sell?"}]

for turn in range(5):
    content, calls = "", []
    for chunk in client.chat_completion(messages, model=model, tools=datacircle_tools(), stream=True):
        delta = chunk.choices[0].delta
        content += delta.content or ""
        collect_tool_calls(calls, delta.tool_calls)
    if not calls:
        print(content)
        break
    messages.append({"role": "assistant", "content": content, "tool_calls": calls})
    messages.extend(call_all(calls))
```

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

## 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
import json

from huggingface_hub_datacircle import call

for tool_call in response.choices[0].message.tool_calls or []:
    message = call(tool_call)
    if message is None:
        arguments = tool_call.function.arguments
        if isinstance(arguments, str):
            arguments = json.loads(arguments)
        output = my_tools[tool_call.function.name](**arguments)
        message = {"role": "tool", "tool_call_id": tool_call.id, "name": tool_call.function.name, "content": str(output)}
    messages.append(message)
```

To give the model only some of the tools, list their names: `datacircle_tools(["datacircle_best_plans"])`.

## 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 huggingface_hub_datacircle import run

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

## 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`.

For an unknown slug, the tool returns `{"error": "..."}` with the API's message. The error for an unknown API slug lists every valid slug. The tool checks each number from the model before any API call. 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 tool never raises an error. 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's spec: https://api.datacircle.dev/v1/openapi.json

MIT license.
