> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mitu.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mitu.ai/_mcp/server.

# Python SDK configuration

You configure the SDK once, when you create the `Mitu` client. The constructor checks your arguments straight away, so a mistake such as a malformed key or an unknown currency raises a [`MituConfigError`](/sdks/python/errors) when your application starts, rather than on the first paying request.

```python
import os

from mitulabs_payments import Mitu

mitu = Mitu(os.environ["MITU_API_KEY"], default_currency="USD")
```

## Arguments

| Argument           | Type  | Description                                                                                                                                     |
| ------------------ | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `api_key`          | `str` | Required, passed as the first positional argument. Your Mitu secret key, either a test key or a live key. It is only ever sent to the Mitu API. |
| `default_currency` | `str` | Optional, passed by keyword and defaults to USD. The currency used for any price that does not name its own.                                    |

## Sandbox and production

Your key decides which Mitu environment the SDK connects to, so there is no separate environment argument.

| Key      | Environment | Mitu API address                                   |
| -------- | ----------- | -------------------------------------------------- |
| Test key | Sandbox     | [https://sandbox.mitu.ai](https://sandbox.mitu.ai) |
| Live key | Production  | [https://api.mitu.ai](https://api.mitu.ai)         |

Use a sandbox key while you develop and test, and switch to a live key when you are ready to accept real payments. Any other value raises a `MituConfigError`. You can check which environment a client is using by reading `mitu.environment`, which is either sandbox or production.

## Default currency

Most APIs price everything in one currency. Setting `default_currency` means you only have to write the amount on each route. A route can still name a different currency when it needs to.

```python
mitu = Mitu(os.environ["MITU_API_KEY"], default_currency="NGN")

mitu.charge(amount="2500")                  # charges 2,500 NGN
mitu.charge(amount="0.05", currency="USD")  # charges 0.05 USD instead
```

A currency is written as a short code such as USD or NGN, and it must be enabled on your Mitu account. When a route is priced in a currency other than the one the caller pays in, Mitu converts the amount at a rate it locks when the payment is created.

## Logging

The SDK writes its log messages through Python's standard `logging` module, under a logger named `mitulabs_payments`. Nothing is shown until you turn it on, which you can do in the same way as for any other library.

```python
import logging

logging.getLogger("mitulabs_payments").setLevel(logging.INFO)
```

The SDK takes care never to log anything sensitive. Its messages never include your API key, a payment credential or the body of a request.

## Shutting down

The client keeps a pool of HTTP connections open to Mitu so that each request is fast. When your application stops, close the client to release those connections. Use `close()` in async applications and `close_sync()` in sync ones.

#### Async applications

In FastAPI, close the client in the application's lifespan handler.

```python
from contextlib import asynccontextmanager


@asynccontextmanager
async def lifespan(app: FastAPI):
    yield
    await mitu.close()


app = FastAPI(lifespan=lifespan)
```

#### Sync applications

In Flask or Django, register the close method to run when the process exits.

```python
import atexit

atexit.register(mitu.close_sync)
```