Skip to main content

Unofficial Keygen SDK for Python. Integrate license activation and offline licensing. Wrapper around keygen-rs rust crate

Project description

Unofficial Keygen Python SDK

The keygen-py package allows Python programs to license using the keygen.sh service. This is a wrapper around the rust package keygen-rs (so a lot of kudos there) to provide python bindings.

Installing

Add this to your pyproject.toml:

[dependencies]
keygen-py = "0.0.1.dev1"

Config

KeygenConfig

Use KeygenConfig to configure the SDK globally. You should set this before making any API calls.

from keygen_sh import set_config, KeygenConfig

set_config(KeygenConfig(
    api_url="https://api.keygen.sh",
    api_prefix="v1",
    api_version="v1.7",
    account="YOUR_KEYGEN_ACCOUNT_ID",
    product="YOUR_KEYGEN_PRODUCT_ID",
    license_key="A_KEYGEN_LICENSE_KEY",
    public_key="YOUR_KEYGEN_PUBLIC_KEY"
))

Usage

Validate a License

To validate a license, configure KeygenConfig with your Keygen account details. Then call the validate function with a device fingerprint (you can use py-machineid for this) or keep it empty depending on your policy:

import asyncio
from keygen_sh import validate

async def amain():
    data = await validate(["YOUR_DEVICE_FINGERPRINT"], [])
    
    # License
    print(data.id, data.name, data.key, data.expiry)

if __name__ == '__main__':
    asyncio.run(amain())

Offline License Key Verification

To verify a signed license key offline:

from keygen_sh import verify, SchemeCode

data = verify(SchemeCode.Ed25519Sign, "A_KEYGEN_LICENSE_KEY")

# data encoded
print(data)

Examples

For more detailed examples, please refer to the examples directory in the repository.

Testing

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.

Inspired by

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

keygen_py-0.0.1.dev2-cp312-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12 Windows x86-64

keygen_py-0.0.1.dev2-cp312-cp312-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.34+ x86-64

keygen_py-0.0.1.dev2-cp312-cp312-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

keygen_py-0.0.1.dev2-cp311-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

keygen_py-0.0.1.dev2-cp311-cp311-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.34+ x86-64

keygen_py-0.0.1.dev2-cp311-cp311-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

keygen_py-0.0.1.dev2-cp310-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

keygen_py-0.0.1.dev2-cp310-cp310-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

keygen_py-0.0.1.dev2-cp310-cp310-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

keygen_py-0.0.1.dev2-cp39-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

keygen_py-0.0.1.dev2-cp39-cp39-manylinux_2_34_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

keygen_py-0.0.1.dev2-cp39-cp39-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

File details

Details for the file keygen_py-0.0.1.dev2-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 458017376635a985dfd520a560ccad43e421ca70c037d50197a23fa4a3f65f84
MD5 302eaf6b918e902b31405223988063fc
BLAKE2b-256 035f484195cacfc449a533b0644a88fea1648b4626986fda92cf72075b5302b8

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 06807e7adaac38af99e473b195771b2a1cc755c1f002f1c332b52b687c8a44cc
MD5 78e26345042c4a2765cffc6f9158405c
BLAKE2b-256 56f9fa81eb0ef87a2d53584e889192bf90470a9fa25057a9a9667f872c1f42d5

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f3b81b9fe43a35952b95083f6340d0cd8ac37556b8fefac2de31a213c949c91
MD5 a4cbe0938eee973bbb9fe3d6edcc1e5e
BLAKE2b-256 277013cdaf0326370d915c73a8f654fb65b3c1090692ee726d124cd90a3cae0b

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 15ca4ac31f86ae30cad79e6ba721aeae3d79af8dca4c8179a2c8090bac5d1849
MD5 77ce85a4765971860c2c15d9ac8c5bfd
BLAKE2b-256 2034a7ff68f6de6633874ff88fb8452182ad3f0dae4e6eaafc35161f5a12604c

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 988bfc07cdec710a2607fef25634f4113ec5dfd0866a42d89e4491064591260d
MD5 3d97cde74830dff211a7a5dd1f498379
BLAKE2b-256 795d4318f382ac7deaac8ade4ad7f0381f794ced4bc24143b1b54fbf15f4b2c8

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6f0ea01627b0a4194cd567566a51ea1f0132b318da45054d5087e94c5f6aaea0
MD5 4706fe31b448a72deab494ea2ca368d6
BLAKE2b-256 88617a6b61106bfb30d55e6962ca21566af2f48b88a4b3eb0744ccdbd5182f6c

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 a0ce9105c06e5497883b84819ae387a5c07b385a1bcf062834a4c2816eb57fde
MD5 00d930d6a4e822511235cf52353a4c7c
BLAKE2b-256 702d65755f29eb79f6f5bfdc0a51f4319ed6ad8d1b3492d5ad1d59d3b1ceef8a

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9ece8992f4d09cc5c5d0eba7403b2adf4a4da7fe10f749aba1fa8e31a2f8cc12
MD5 d6ab58f0200629bd5a826b5d36f99cc9
BLAKE2b-256 1f6944183ae0839a9a7677f92d20371dbef1a4fbdc27db0c383cbd12ab60ed48

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d619d485e9bb351f483269d184943e18af34f6649d8267f34e1cf85caf251d63
MD5 301ba875b3957327892512e1378ceb87
BLAKE2b-256 54ab861f13acd17645078cee3e020377c3b5d2de8a305ade53257d87bd02e6ba

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 8c965f113821b4ca1c8001d6bd1248141a5f75348ac2af46bef900b329b73849
MD5 7d071d1e408e6a424b544bcc1719ed9b
BLAKE2b-256 c36c4e577c56f74005f4f5d577cb2c1ae5ad4a446428ebbdc2e7d035b83e0a7b

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f727530955059cd90c8797a5553b3ea31e444a15197545301ddd30e72475dec0
MD5 54c0db1d59da0ae3d5d2e569a941e4b7
BLAKE2b-256 cf601cc14cc081c5ddd8aa560265f8ebd1888f07131a82d96076bcdc96e4cd8c

See more details on using hashes here.

File details

Details for the file keygen_py-0.0.1.dev2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 131b124291935e9f8822a51a8ec0bb7efece672c3c35bd2959cce39ebe73da3e
MD5 79992057c4da1ddbd69f39da51e47208
BLAKE2b-256 67ca19c322cb499b49bcaa42f1a7383ec38bcf934a1228850445ddb2e84f2984

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page