> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rhetoric.law/llms.txt
> Use this file to discover all available pages before exploring further.

# Client libraries

> Official Rhetoric client libraries for TypeScript, Python, and Rust.

Rhetoric publishes official client libraries for TypeScript, Python, and Rust.
Each one exposes every operation in the [API reference](/api-reference/introduction)
with typed inputs and outputs, so you can call Rhetoric without hand-writing
HTTP requests. They are meant to be used on your backend, where your API key
lives.

| Language | Package | Registry |
| - | - | - |
| TypeScript | `@rhetoriclabs/rhetoric` | [npm](https://www.npmjs.com/package/@rhetoriclabs/rhetoric) |
| Python | `rhetoric_py` | [PyPI](https://pypi.org/project/rhetoric-py/) |
| Rust | `rhetoric` | [crates.io](https://crates.io/crates/rhetoric) |

## Install

<CodeGroup>
  ```shell TypeScript theme={null}
  npm install @rhetoriclabs/rhetoric
  ```

  ```shell Python theme={null}
  pip install rhetoric_py
  ```

  ```shell Rust theme={null}
  cargo add rhetoric
  ```
</CodeGroup>

The Python package is installed as `rhetoric_py` but imported as `rhetoric`.

## Create a client

Every client takes the API URL and an [API key](/guides/quickstart#create-an-api-key).
Keep the key on your backend.

<CodeGroup>
  ```ts TypeScript theme={null}
  import { RhetoricClient } from "@rhetoriclabs/rhetoric";

  const client = new RhetoricClient({
    url: "https://api.rhetoric.law",
    token: process.env.RHETORIC_API_KEY,
  });
  ```

  ```python Python theme={null}
  import os

  from rhetoric import RhetoricClient

  client = RhetoricClient(
      url="https://api.rhetoric.law",
      token=os.environ["RHETORIC_API_KEY"],
  )
  ```

  ```rust Rust theme={null}
  use rhetoric::RhetoricClient;

  let client = RhetoricClient::new(
      "https://api.rhetoric.law",
      std::env::var("RHETORIC_API_KEY")?,
  );
  ```
</CodeGroup>

## Make a request

Operations are methods on the client. This example creates a filer and then
starts a filing session for them.

<CodeGroup>
  ```ts TypeScript theme={null}
  const { filer } = await client.createFiler({});

  const { session, sessionToken } = await client.createFilingSession({
    filerId: filer.id,
  });
  ```

  ```python Python theme={null}
  from rhetoric import CreateFilerInput, CreateFilingSessionInput

  # The Python client is async. Run this inside a coroutine.
  out = await client.create_filer(CreateFilerInput())

  out = await client.create_filing_session(
      CreateFilingSessionInput(filer_id=out.filer.id)
  )
  session, session_token = out.session, out.session_token
  ```

  ```rust Rust theme={null}
  use rhetoric::{CreateFilerInput, CreateFilingSessionInput};

  let req = CreateFilerInput {};
  let filer = client.create_filer(req).await?.filer;

  let req = CreateFilingSessionInput { filer_id: filer.id };
  let out = client.create_filing_session(req).await?;
  let (session, session_token) = (out.session, out.session_token);
  ```
</CodeGroup>

The session token is only returned once, at creation time. [Pass it to your
frontend](/guides/quickstart#pass-the-session-token-to-your-frontend) so the
[Element](/element/introduction) can
drive the session.

## Error handling

Each library reports failures in the way that is idiomatic for its language:

* **TypeScript** throws an error when an operation fails.
* **Python** raises an exception when an operation fails.
* **Rust** returns an `Err` when an operation fails.

## Command line

If you would rather explore the API from a terminal, the [Rhetoric
CLI](/cli-reference/introduction) exposes the same operations as commands.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.