|
| 1 | +# KeyMint Python SDK |
| 2 | + |
| 3 | +Welcome to the official KeyMint SDK for Python! This library provides a simple and convenient way to interact with the KeyMint API, allowing you to manage license keys for your applications with ease. |
| 4 | + |
| 5 | +## ✨ Features |
| 6 | + |
| 7 | +* **Simple & Intuitive**: A clean and modern API that is easy to learn and use. |
| 8 | +* **Type Hinting**: Uses Python's type hinting for a better developer experience. |
| 9 | +* **Comprehensive**: Covers all the essential KeyMint API endpoints. |
| 10 | +* **Well-Documented**: Clear and concise documentation with plenty of examples. |
| 11 | +* **Error Handling**: Standardized error handling to make debugging a breeze. |
| 12 | + |
| 13 | +## 🚀 Quick Start |
| 14 | + |
| 15 | +Here's a complete example of how to use the SDK to create and activate a license key: |
| 16 | + |
| 17 | +```python |
| 18 | +import os |
| 19 | +from keymint import KeyMintSDK |
| 20 | + |
| 21 | +def main(): |
| 22 | + access_token = os.environ.get('KEYMINT_ACCESS_TOKEN') |
| 23 | + if not access_token: |
| 24 | + print('Please set the KEYMINT_ACCESS_TOKEN environment variable.') |
| 25 | + return |
| 26 | + |
| 27 | + sdk = KeyMintSDK(access_token) |
| 28 | + |
| 29 | + try: |
| 30 | + # 1. Create a new license key |
| 31 | + create_response = sdk.create_key({ |
| 32 | + 'productId': 'YOUR_PRODUCT_ID', |
| 33 | + }) |
| 34 | + license_key = create_response['key'] |
| 35 | + print(f'Key created: {license_key}') |
| 36 | + |
| 37 | + # 2. Activate the license key |
| 38 | + activate_response = sdk.activate_key({ |
| 39 | + 'productId': 'YOUR_PRODUCT_ID', |
| 40 | + 'licenseKey': license_key, |
| 41 | + 'hostId': 'UNIQUE_DEVICE_ID', |
| 42 | + }) |
| 43 | + print(f"Key activated: {activate_response['message']}") |
| 44 | + except Exception as e: |
| 45 | + print(f'An error occurred: {e}') |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + main() |
| 49 | +``` |
| 50 | + |
| 51 | +## 📦 Installation |
| 52 | + |
| 53 | +```bash |
| 54 | +pip install keymint |
| 55 | +``` |
| 56 | + |
| 57 | +## 🛠️ Usage |
| 58 | + |
| 59 | +### Initialization |
| 60 | + |
| 61 | +First, import the `KeyMintSDK` and initialize it with your access token. You can find your access token in your [KeyMint dashboard](https://keymint.dev/app/settings/api). |
| 62 | + |
| 63 | +```python |
| 64 | +from keymint import KeyMintSDK |
| 65 | + |
| 66 | +access_token = 'YOUR_ACCESS_TOKEN' |
| 67 | +sdk = KeyMintSDK(access_token) |
| 68 | +``` |
| 69 | + |
| 70 | +### API Methods |
| 71 | + |
| 72 | +All methods return a dictionary. |
| 73 | + |
| 74 | +| Method | Description | |
| 75 | +| --------------- | ----------------------------------------------- | |
| 76 | +| `create_key` | Creates a new license key. | |
| 77 | +| `activate_key` | Activates a license key for a device. | |
| 78 | +| `deactivate_key`| Deactivates a device from a license key. | |
| 79 | +| `get_key` | Retrieves detailed information about a key. | |
| 80 | +| `block_key` | Blocks a license key. | |
| 81 | +| `unblock_key` | Unblocks a previously blocked license key. | |
| 82 | + |
| 83 | +For more detailed information about the API methods and their parameters, please refer to the [API Reference](#api-reference) section below. |
| 84 | + |
| 85 | +## 🚨 Error Handling |
| 86 | + |
| 87 | +If an API call fails, the SDK will raise a `KeyMintApiError` exception. This object contains a `message`, `code`, and `status` attribute that you can use to handle the error. |
| 88 | + |
| 89 | +```python |
| 90 | +from keymint import KeyMintApiError |
| 91 | + |
| 92 | +try: |
| 93 | + # ... |
| 94 | +except KeyMintApiError as e: |
| 95 | + print(f'API Error: {e.message}') |
| 96 | + print(f'Status: {e.status}') |
| 97 | + print(f'Code: {e.code}') |
| 98 | +except Exception as e: |
| 99 | + print(f'An unexpected error occurred: {e}') |
| 100 | +``` |
| 101 | + |
| 102 | +## 📚 API Reference |
| 103 | + |
| 104 | +### `KeyMintSDK(access_token, base_url)` |
| 105 | + |
| 106 | +| Parameter | Type | Description | |
| 107 | +| -------------- | -------- | --------------------------------------------------------------------------- | |
| 108 | +| `access_token` | `str` | **Required.** Your KeyMint API access token. | |
| 109 | +| `base_url` | `str` | *Optional.* The base URL for the KeyMint API. Defaults to `https://api.keymint.dev`. | |
| 110 | + |
| 111 | +### `create_key(params)` |
| 112 | + |
| 113 | +| Parameter | Type | Description | |
| 114 | +| ---------------- | -------- | --------------------------------------------------------------------------- | |
| 115 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 116 | +| `maxActivations` | `str` | *Optional.* The maximum number of activations for the key. | |
| 117 | +| `expiryDate` | `str` | *Optional.* The expiration date of the key in ISO 8601 format. | |
| 118 | +| `customerId` | `str` | *Optional.* The ID of an existing customer to associate with the key. | |
| 119 | +| `newCustomer` | `dict` | *Optional.* A dictionary containing the name and email of a new customer. | |
| 120 | + |
| 121 | +### `activate_key(params)` |
| 122 | + |
| 123 | +| Parameter | Type | Description | |
| 124 | +| ------------ | -------- | --------------------------------------------------------------------------- | |
| 125 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 126 | +| `licenseKey` | `str` | **Required.** The license key to activate. | |
| 127 | +| `hostId` | `str` | *Optional.* A unique identifier for the device. | |
| 128 | +| `deviceTag` | `str` | *Optional.* A user-friendly name for the device. | |
| 129 | + |
| 130 | +### `deactivate_key(params)` |
| 131 | + |
| 132 | +| Parameter | Type | Description | |
| 133 | +| ------------ | -------- | --------------------------------------------------------------------------- | |
| 134 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 135 | +| `licenseKey` | `str` | **Required.** The license key to deactivate. | |
| 136 | +| `hostId` | `str` | *Optional.* The ID of the device to deactivate. If omitted, all devices are deactivated. | |
| 137 | + |
| 138 | +### `get_key(params)` |
| 139 | + |
| 140 | +| Parameter | Type | Description | |
| 141 | +| ------------ | -------- | --------------------------------------------------------------------------- | |
| 142 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 143 | +| `licenseKey` | `str` | **Required.** The license key to retrieve. | |
| 144 | + |
| 145 | +### `block_key(params)` |
| 146 | + |
| 147 | +| Parameter | Type | Description | |
| 148 | +| ------------ | -------- | --------------------------------------------------------------------------- | |
| 149 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 150 | +| `licenseKey` | `str` | **Required.** The license key to block. | |
| 151 | + |
| 152 | +### `unblock_key(params)` |
| 153 | + |
| 154 | +| Parameter | Type | Description | |
| 155 | +| ------------ | -------- | --------------------------------------------------------------------------- | |
| 156 | +| `productId` | `str` | **Required.** The ID of the product. | |
| 157 | +| `licenseKey` | `str` | **Required.** The license key to unblock. | |
| 158 | + |
| 159 | +## 📜 License |
| 160 | + |
| 161 | +This SDK is licensed under the MIT License. |
0 commit comments