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

# Python SDK

> Install and configure the mag3nt Python SDK.

## Installation

```bash theme={null}
pip install mag3nt
```

## Setup

```python theme={null}
import mag3nt
from mag3nt.models.components import Security
import os

sdk = mag3nt.Mag3nt(
    server_url="https://mag3nt.com",
    security=Security(bearer_auth=os.environ["MAG3NT_API_KEY"]),
)
```

## Usage

```python theme={null}
# Issue a card
card = sdk.cards.cards_create(
    purpose="Research Agent",
    limit_amount=50,
)

# Check balance
balance = sdk.funding.funding_get_balance()

# Pay for an API
payment = sdk.payments.payments_execute(
    card_id=card.card.id,
    card_token=card.card.token,
    url="https://api.weather.com/forecast"
)

# List transactions
txns = sdk.cards.cards_list_transactions(id=card.card.id)
```

## Async support

Every method has an async variant with the `_async` suffix:

```python theme={null}
import asyncio

async def main():
    cards = await sdk.cards.cards_list_async()
    balance = await sdk.funding.funding_get_balance_async()

asyncio.run(main())
```

## Error handling

```python theme={null}
from mag3nt.models.errors import BalanceError, Mag3ntError

try:
    sdk.cards.cards_create(purpose="Agent", limit_amount=100)
except BalanceError as e:
    print(f"Need {e.requested}, have {e.available}")
except Mag3ntError as e:
    print(f"Error: {e.status_code}")
```

## Available methods

| Module           | Description                               |
| ---------------- | ----------------------------------------- |
| `sdk.keys`       | API key management                        |
| `sdk.cards`      | Card issuance, controls, and transactions |
| `sdk.funding`    | Balance and deposits                      |
| `sdk.payments`   | Universal outbound payment engine         |
| `sdk.x402`       | x402 protocol payments (deprecated)       |
| `sdk.ap2`        | Agent-to-agent payments                   |
| `sdk.mpp`        | Micropayment streaming                    |
| `sdk.pay_links`  | Shareable payment links                   |
| `sdk.settlement` | Settlement status                         |
| `sdk.status`     | Platform health                           |

See the [API Reference](/api-reference/cards/list-all-cards-for-the-authenticated-wallet) for full method documentation.
