keygen-py 0.0.1.dev3__cp310-none-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keygen_py-0.0.1.dev3.dist-info/METADATA +95 -0
- keygen_py-0.0.1.dev3.dist-info/RECORD +8 -0
- keygen_py-0.0.1.dev3.dist-info/WHEEL +4 -0
- keygen_py-0.0.1.dev3.dist-info/licenses/LICENSE +21 -0
- keygen_sh/__init__.py +5 -0
- keygen_sh/__init__.pyi +62 -0
- keygen_sh/keygen_sh.cp310-win32.pyd +0 -0
- keygen_sh/py.typed +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: keygen-py
|
|
3
|
+
Version: 0.0.1.dev3
|
|
4
|
+
License-File: LICENSE
|
|
5
|
+
Summary: Unofficial Keygen SDK for Python. Integrate license activation and offline licensing. Wrapper around keygen-rs rust crate
|
|
6
|
+
Author-email: Terra Quantum AG <info@terraquantum.swiss>, Cedric Kring <ck@terraquantum.swiss>, Steven Beckers <sb@terraquantum.swiss>
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
10
|
+
|
|
11
|
+
# Unofficial Keygen Python SDK
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
The `keygen-py` package allows Python programs to license using the [keygen.sh](https://keygen.sh) service.
|
|
15
|
+
This is a wrapper around the rust package [keygen-rs](https://github.com/ahonn/keygen-rs) (so a lot of kudos there) to provide python bindings.
|
|
16
|
+
|
|
17
|
+
## Installing
|
|
18
|
+
|
|
19
|
+
Add this to your `pyproject.toml`:
|
|
20
|
+
|
|
21
|
+
```toml
|
|
22
|
+
[dependencies]
|
|
23
|
+
keygen-py = "0.0.1.dev1"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Config
|
|
27
|
+
|
|
28
|
+
### KeygenConfig
|
|
29
|
+
|
|
30
|
+
Use `KeygenConfig` to configure the SDK globally. You should set this before making any API calls.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from keygen_sh import set_config, KeygenConfig
|
|
34
|
+
|
|
35
|
+
set_config(KeygenConfig(
|
|
36
|
+
api_url="https://api.keygen.sh",
|
|
37
|
+
api_prefix="v1",
|
|
38
|
+
api_version="v1.7",
|
|
39
|
+
account="YOUR_KEYGEN_ACCOUNT_ID",
|
|
40
|
+
product="YOUR_KEYGEN_PRODUCT_ID",
|
|
41
|
+
license_key="A_KEYGEN_LICENSE_KEY",
|
|
42
|
+
public_key="YOUR_KEYGEN_PUBLIC_KEY"
|
|
43
|
+
))
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Validate a License
|
|
49
|
+
|
|
50
|
+
To validate a license, configure `KeygenConfig` with your Keygen account details. Then call the `validate` function with a device fingerprint
|
|
51
|
+
(you can use [py-machineid](https://github.com/keygen-sh/py-machineid/tree/master) for this) or keep it empty depending on your policy:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
from keygen_sh import validate
|
|
56
|
+
|
|
57
|
+
async def amain():
|
|
58
|
+
data = await validate(["YOUR_DEVICE_FINGERPRINT"], [])
|
|
59
|
+
|
|
60
|
+
# License
|
|
61
|
+
print(data.id, data.name, data.key, data.expiry)
|
|
62
|
+
|
|
63
|
+
if __name__ == '__main__':
|
|
64
|
+
asyncio.run(amain())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Offline License Key Verification
|
|
68
|
+
|
|
69
|
+
To verify a signed license key offline:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from keygen_sh import verify, SchemeCode
|
|
73
|
+
|
|
74
|
+
data = verify(SchemeCode.Ed25519Sign, "A_KEYGEN_LICENSE_KEY")
|
|
75
|
+
|
|
76
|
+
# data encoded
|
|
77
|
+
print(data)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
For more detailed examples, please refer to the `examples` directory in the repository.
|
|
84
|
+
|
|
85
|
+
## Testing
|
|
86
|
+
|
|
87
|
+
When implementing a testing strategy for your licensing integration, we recommend mocking the Keygen API responses. This is especially important for CI/CD environments to prevent unnecessary load on Keygen's servers and to stay within your account's daily request limits.
|
|
88
|
+
|
|
89
|
+
## Inspired by
|
|
90
|
+
- [keygen-rs](https://github.com/ahonn/keygen-rs)
|
|
91
|
+
- [keygen-go](https://github.com/keygen-sh/keygen-go)
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
keygen_py-0.0.1.dev3.dist-info/METADATA,sha256=MIAE36QjN9TLFSC66cMu2SH_g9mhdTjSx54gcsNG-ww,2756
|
|
2
|
+
keygen_py-0.0.1.dev3.dist-info/WHEEL,sha256=Pw1rTMFEM9YbMRCplAtTLegt9HMzeR45FiD03Pwyddc,91
|
|
3
|
+
keygen_py-0.0.1.dev3.dist-info/licenses/LICENSE,sha256=5W4k6elGLWpPjS9hZlcL_KAwnmEDKfeO3Lu-jhA3pkY,1092
|
|
4
|
+
keygen_sh/__init__.py,sha256=g3y8VIMBnmnm2jCciRWMowXn-4mRr6h8qsGo-zQQh3o,119
|
|
5
|
+
keygen_sh/__init__.pyi,sha256=U385Sy5ZWMFccJNrM9fyEjl1Wz9DTj07Eg92F3KXwdQ,1567
|
|
6
|
+
keygen_sh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
keygen_sh/keygen_sh.cp310-win32.pyd,sha256=_1AlRPtFxJeMpv2j4L3q1AnZ4k0dqzuV-nZ63uALUBg,3031040
|
|
8
|
+
keygen_py-0.0.1.dev3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Terra Quantum AG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
keygen_sh/__init__.py
ADDED
keygen_sh/__init__.pyi
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from enum import Enum, auto
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
class KeygenConfig:
|
|
6
|
+
def __init__(
|
|
7
|
+
self,
|
|
8
|
+
api_url: str,
|
|
9
|
+
api_version: str,
|
|
10
|
+
api_prefix: str,
|
|
11
|
+
account: str,
|
|
12
|
+
product: str,
|
|
13
|
+
package: Optional[str] = "",
|
|
14
|
+
environment: Optional[str] = None,
|
|
15
|
+
license_key: Optional[str] = None,
|
|
16
|
+
token: Optional[str] = None,
|
|
17
|
+
public_key: Optional[str] = None,
|
|
18
|
+
platform: Optional[str] = None,
|
|
19
|
+
user_agent: Optional[str] = None,
|
|
20
|
+
max_clock_drift: Optional[int] = 5,
|
|
21
|
+
): ...
|
|
22
|
+
|
|
23
|
+
class SchemeCode(Enum):
|
|
24
|
+
Ed25519Sign = auto()
|
|
25
|
+
|
|
26
|
+
class License:
|
|
27
|
+
id: str
|
|
28
|
+
scheme: SchemeCode
|
|
29
|
+
key: str
|
|
30
|
+
name: Optional[str]
|
|
31
|
+
expiry: Optional[str]
|
|
32
|
+
status: Optional[str]
|
|
33
|
+
policy: Optional[str]
|
|
34
|
+
|
|
35
|
+
def verify(scheme: SchemeCode, key: str) -> str:
|
|
36
|
+
"""
|
|
37
|
+
Verify an offline key.
|
|
38
|
+
|
|
39
|
+
:param scheme: the scheme code
|
|
40
|
+
:param key: the key to verify
|
|
41
|
+
:return: the data in the key
|
|
42
|
+
:raises: ValueError if the key is invalid
|
|
43
|
+
"""
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
async def validate(fingerprints: Optional[list[str]] = None, entitlements: Optional[list[str]] = None) -> License:
|
|
47
|
+
"""
|
|
48
|
+
Validate a license.
|
|
49
|
+
|
|
50
|
+
:param fingerprints: optionally, the fingerprints
|
|
51
|
+
:param entitlements: optionally, the entitlements
|
|
52
|
+
:raises: RuntimeError if the license is invalid
|
|
53
|
+
"""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def set_config(config: KeygenConfig) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Set the global configuration.
|
|
59
|
+
|
|
60
|
+
:param config: a configuration object
|
|
61
|
+
"""
|
|
62
|
+
...
|
|
Binary file
|
keygen_sh/py.typed
ADDED
|
File without changes
|