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

# Python

> Use the official KeyPort Python package from PyPI to validate license keys and retrieve license details.

## Installation

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install keyport
```

## Setup and usage

<Steps>
  <Step title="Initialize the client">
    Import `KeyPort` and create a client with your API key, or load it from a config file:

    <CodeGroup>
      ```python API key in code theme={"theme":{"light":"github-light","dark":"github-dark"}}
      from keyport import KeyPort

      client = KeyPort(api_key='kp_live_xxx')
      ```

      ```python Config file theme={"theme":{"light":"github-light","dark":"github-dark"}}
      from keyport import KeyPort

      client = KeyPort.from_config_file('./keyport.json')
      ```
    </CodeGroup>
  </Step>

  <Step title="Validate a license key">
    Call `client.validate` with the license key you want to check:

    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    result = client.validate('ABCD-EFGH-IJKL-MNOP')
    ```

    This sends a `POST /api/v1/validate` request and returns the validation result.
  </Step>

  <Step title="Retrieve license details">
    Call `client.get_license` with the license key to fetch full license details:

    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    detail = client.get_license('ABCD-EFGH-IJKL-MNOP')
    ```

    This sends a `GET /api/v1/license/:key` request and returns the license detail object.
  </Step>
</Steps>

## Full examples

<CodeGroup>
  ```python API key in code theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from keyport import KeyPort

  client = KeyPort(api_key='kp_live_xxx')

  # Validate a license key
  result = client.validate('ABCD-EFGH-IJKL-MNOP')

  # Retrieve full license details
  detail = client.get_license('ABCD-EFGH-IJKL-MNOP')
  ```

  ```python Config file theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from keyport import KeyPort

  client = KeyPort.from_config_file('./keyport.json')

  # Retrieve full license details
  detail = client.get_license('ABCD-EFGH-IJKL-MNOP')
  ```
</CodeGroup>

<Tip>
  Store your API key in an environment variable or a `keyport.json` config file rather than hard-coding it in your source code.
</Tip>
