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

# unkey.py

> Reference for the unkey.py Python SDK. Create, verify, update, and revoke API keys programmatically from your Python application or service.

## SDK Installation

> \[!NOTE] > **Python version upgrade policy**
>
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.

The SDK can be installed with either *pip* or *poetry* package managers.

### PIP

*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.

```bash theme={"theme":"kanagawa-wave"}
pip install unkey.py
```

### Poetry

*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.

```bash theme={"theme":"kanagawa-wave"}
poetry add unkey.py
```

### Shell and script usage with `uv`

You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:

```shell theme={"theme":"kanagawa-wave"}
uvx --from unkey.py python
```

It's also possible to write a standalone Python script without needing to set up a whole project like so:

```python theme={"theme":"kanagawa-wave"}
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
#     "unkey.py",
# ]
# ///

from unkey.py import Unkey

sdk = Unkey(
  # SDK arguments
)

# Rest of script here...
```

Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.

## SDK Example Usage

### Example

```python theme={"theme":"kanagawa-wave"}
# Synchronous Example
from unkey.py import Unkey


with Unkey(
    root_key="<YOUR_BEARER_TOKEN_HERE>",
) as unkey:

    res = unkey.apis.create_api(name="payment-service-production")

    # Handle response
    print(res)
```

The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python theme={"theme":"kanagawa-wave"}
# Asynchronous Example
import asyncio
from unkey.py import Unkey

async def main():

    async with Unkey(
        root_key="<YOUR_BEARER_TOKEN_HERE>",
    ) as unkey:

        res = await unkey.apis.create_api_async(name="payment-service-production")

        # Handle response
        print(res)

asyncio.run(main())
```

## Repository

<Card title="GitHub" icon="github" href="https://github.com/unkeyed/sdks/blob/main/api/py/README.md" cta="README">
  The full autogenerated documentation can be found on GitHub.
</Card>
