Metadata-Version: 2.5
Name: langchain-converter-studio
Version: 1.0.0
Summary: LangChain tools for Converter Studio: convert files and links to other formats, read scanned PDFs and images with OCR, and compress PDFs.
Project-URL: Homepage, https://converter.studio
Project-URL: Documentation, https://converter.studio/developers
Project-URL: Source, https://github.com/tariksucu/langchain-converter-studio
Project-URL: Issues, https://github.com/tariksucu/langchain-converter-studio/issues
Project-URL: Changelog, https://github.com/tariksucu/langchain-converter-studio/blob/main/CHANGELOG.md
Author-email: Converter Studio <support@converter.studio>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,converter-studio,file-conversion,langchain,langchain-tools,ocr,pdf
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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 :: Multimedia :: Graphics :: Graphics Conversion
Classifier: Topic :: Office/Business
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.11
Requires-Dist: converter-studio<2,>=1.0
Requires-Dist: httpx<1,>=0.27
Requires-Dist: langchain-core<2,>=1.4
Requires-Dist: pydantic<3,>=2.7.4
Description-Content-Type: text/markdown

# langchain-converter-studio

LangChain tools for [Converter Studio](https://converter.studio): an agent can convert files and
links to other formats, read the text of scanned PDFs and photos with OCR, make PDFs smaller and
look up what a file can become. The work runs on Converter Studio's servers through its
[API](https://converter.studio/developers), so there is nothing else to install: no LibreOffice,
no FFmpeg, no Tesseract.

| Tool                         | Name                            | What the agent gets back                                                    |
| ---------------------------- | ------------------------------- | --------------------------------------------------------------------------- |
| `ConverterStudioConvert`     | `converter_studio_convert`      | the new file's download link, and the file in the working directory         |
| `ConverterStudioExtractText` | `converter_studio_extract_text` | the recognised text of a scanned PDF or a picture (JPG, PNG, WebP, HEIC...) |
| `ConverterStudioCompressPdf` | `converter_studio_compress_pdf` | the sizes before and after, the smaller PDF's link and file                 |
| `ConverterStudioListFormats` | `converter_studio_list_formats` | what a format, extension or file name can become (free, no key)             |

`ConverterStudioToolkit` gives an agent all four, with one set of settings.

Converter Studio reads documents (Word, PDF, ODT, RTF, Markdown, HTML), spreadsheets,
presentations, images and iPhone photos (HEIC, camera RAW, WebP, AVIF), video, audio, e-books,
subtitles, fonts, data files and archives: 67 formats.

## Installation

```console
$ pip install -U langchain-converter-studio
```

Python 3.11 or later and `langchain-core` 1.4 or later. The package uses the official
[Converter Studio Python client](https://github.com/tariksucu/converter-studio-python)
(`converter-studio`), which pip installs with it.

Create an API key on your [account page](https://converter.studio/account#api-keys) (keys start
with `cvs_live_`; a free account works) and put it in the environment:

```console
$ export CONVERTER_STUDIO_API_KEY=cvs_live_...
```

Every conversion uses the account's credits, the same as on the website: free accounts get
credits every day, Pro and Premium their monthly credits. Most files cost 1 credit; text
recognition costs a credit for every ten PDF pages started; audio and video are priced by their
length (video also by its frame size and the format made). See
[pricing](https://converter.studio/pricing). Listing formats is free.

## Quick start

```python
from langchain_converter_studio import ConverterStudioConvert

tool = ConverterStudioConvert(root_dir="documents")
print(tool.invoke({"source": "report.docx", "to": "pdf"}))
```

```text
Converted report.docx (DOCX) to PDF: report.pdf, 52.1 KB, 1 credit.
Saved in the working directory as report.pdf.
Download link (anyone with it can download the file until 2026-11-23 08:00 UTC): https://converter.studio/api/jobs/...
```

## Use it in an agent

The toolkit gives the agent all four tools. This example runs as it is, without a model provider's
key: `ScriptedModel` plays back the tool calls a model would make. It needs `pip install langchain`
for `create_agent`, a `documents` folder with a `report.docx` in it, and your Converter Studio key
in `CONVERTER_STUDIO_API_KEY`.

```python
from langchain.agents import create_agent
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage

from langchain_converter_studio import ConverterStudioToolkit


class ScriptedModel(GenericFakeChatModel):
    """Plays back the messages below instead of calling a model."""

    def bind_tools(self, tools, **kwargs):
        return self


def tool_call(call_id, name, **args):
    return AIMessage("", tool_calls=[{"id": call_id, "name": name, "args": args}])


model = ScriptedModel(
    messages=iter(
        [
            tool_call("1", "converter_studio_list_formats", file_format="report.docx"),
            tool_call("2", "converter_studio_convert", source="report.docx", to="pdf"),
            AIMessage("report.pdf is in the documents folder."),
        ]
    )
)

toolkit = ConverterStudioToolkit(root_dir="documents", max_credits=5)
agent = create_agent(model, tools=toolkit.get_tools())

result = agent.invoke({"messages": [{"role": "user", "content": "Make a PDF of report.docx"}]})
for message in result["messages"]:
    message.pretty_print()
```

With a real model, pass any chat model that supports tool calling instead of `model`, for example
`create_agent("<provider>:<model>", tools=toolkit.get_tools())`. The tools' descriptions and
argument schemas tell the model what each one does.

## The working directory

`root_dir` is the folder the tools work in:

- **With it**, the agent can name local files by their path inside that folder
  (`"report.docx"`, `"scans/invoice.pdf"`), and every result is saved there under its own name.
  A result never replaces a file: it gets `-1`, `-2`... before its extension. Paths that lead out
  of the folder (`../`, absolute paths elsewhere, symbolic links pointing outside) are refused, so
  a model's argument never sends other files on the machine to Converter Studio.
- **Without it**, the tools read no local files: they take `http://` and `https://` links only
  (direct links and Google Drive, Dropbox or OneDrive share links), and give back download links.

## Settings

The toolkit takes all of these keyword arguments, and each tool the ones that apply to it:

| Setting             | Default                                                       | What it does                                                                                            |
| ------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `api_key`           | `CONVERTER_STUDIO_API_KEY`                                    | the account's API key (not needed by `ConverterStudioListFormats`)                                      |
| `root_dir`          | none                                                          | the working directory (above)                                                                           |
| `max_credits`       | `20`                                                          | the most one conversion may cost; a dearer one is refused and costs nothing. The model cannot change it |
| `timeout`           | `600`                                                         | seconds to wait for a conversion to finish                                                              |
| `max_characters`    | `20000`                                                       | the most characters of recognised text returned to the model (`ConverterStudioExtractText`)             |
| `base_url`          | `CONVERTER_STUDIO_BASE_URL` or `https://converter.studio/api` | another address of the API                                                                              |
| `handle_tool_error` | `True`                                                        | tools only: errors go back to the model as the tool's answer; `False` raises `ToolException`            |

## What the tools return

Called with a model's tool call (as an agent calls them), the conversion tools return a
`ToolMessage` whose `content` is the text above and whose `artifact` holds the conversion as a
dict, for your own code:

```python
message = tool.invoke(
    {
        "args": {"source": "report.docx", "to": "pdf"},
        "id": "1",
        "name": tool.name,
        "type": "tool_call",
    }
)
message.artifact["download_url"], message.artifact["saved_path"], message.artifact["credits"]
```

The artifact has `conversion_id`, `status`, `from_format`, `to_format`, `input_name`,
`input_size`, `output_name`, `output_size`, `credits`, `download_url`, `expires_at` and
`saved_path`; `ConverterStudioExtractText` adds `text`, the whole text even when the message shows
only its start.

The conversion tool's arguments are `source`, `to` (`pdf`, `docx`, `jpg`, `mp4`, `mp3`...) and
optional `options`: the API's conversion settings, such as `{"quality": "high"}`,
`{"height": "720"}` for video, `{"maxKb": 200}` for a JPG under a size, `{"pageRange": "1-3"}`,
`{"pdfA": true}` or `{"keepMetadata": true}`. The full list is on the
[API page](https://converter.studio/developers); settings that do not apply are ignored.
`ConverterStudioExtractText` takes `source`, `language` (`auto`, `en`, `de`, `fr`, `es`, `tr`,
`zh`, `ja`... 19 languages) and `page_range`; `ConverterStudioCompressPdf` takes `source` and
`level` (`light`, `balanced`, `strong`).

## Errors

Errors come back to the model as the tool's answer (`status="error"`), in words it can act on or
pass on: the API's own message for a key that does not work, a lack of credits, a file that
cannot be converted ("Your credits were given back") or a format that cannot become another, and
the tool's message for a price over `max_credits`, a conversion that took longer than `timeout`, a
path outside the working directory or a setting with the wrong type. The API key is never part of
an answer.

## Async

Every tool works with `ainvoke` and in async agents (`agent.ainvoke(...)`), with the client's
asynchronous version underneath.

## Limits

- The largest file and the longest audio or video depend on the plan. Results are kept for 6
  hours, then deleted.
- One file in, one file out: no merging or splitting of PDFs.
- Anyone with a download link can download the result until it expires. When an agent run is
  traced (LangSmith, logs), the links in the tools' answers are traced with it.

## Privacy

The files the tools are given are sent to Converter Studio (converter.studio) to be converted.
Uploaded files are deleted as soon as they are converted, and results 6 hours later. Each request
also says which integration sent it (`X-Converter-Studio-Client: langchain/<version>`), for usage
statistics only. See the [privacy policy](https://converter.studio/privacy) and the
[terms](https://converter.studio/terms).

## Development

```console
$ pip install -e . --group dev
$ pytest --disable-socket --allow-unix-socket tests/unit_tests
$ CONVERTER_STUDIO_API_KEY=cvs_live_... pytest tests/integration_tests
```

The unit tests run LangChain's standard tool tests (`langchain-tests`) and the tools inside
`create_agent` against a fake API, without network. The integration tests run LangChain's
standard integration tests against the real API and use 12 credits.

## Links

- Converter Studio: <https://converter.studio>
- API documentation: <https://converter.studio/developers>
- Pricing: <https://converter.studio/pricing>
- Source code and issues: <https://github.com/tariksucu/langchain-converter-studio>
- Changelog: <https://github.com/tariksucu/langchain-converter-studio/blob/main/CHANGELOG.md>
- Support: <support@converter.studio>

MIT licensed. © Converter Studio.
