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.dev1-cp312-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12 Windows x86-64

keygen_py-0.0.1.dev1-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.dev1-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.dev1-cp311-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

keygen_py-0.0.1.dev1-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.dev1-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.dev1-cp310-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

keygen_py-0.0.1.dev1-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.dev1-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.dev1-cp39-none-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

keygen_py-0.0.1.dev1-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.dev1-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.dev1-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 bb61228175d4012add7493be6fa39ae4fe199537c83baf5a3b91bdc87f90847b
MD5 9ac40e02dde7a51a8056ef32d138928c
BLAKE2b-256 742e344cac4e717c2fe6107223c7630d677843e19248929f4d94f023e56929e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6b2b92eb66301c6d1bf94c8014926067b9285fbfbb331177a328b7ba2210f421
MD5 e4e8f239ab989448af30bb2d7f207863
BLAKE2b-256 519d76c4a7757e7d107eef8adca1ddbe33b235c8d9c9de1911df41609943e6ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef90a219c8c1228a3a3a77e4373799e41631184440785366d67d7633a1c7a6a4
MD5 8c9d6c79fe495297e3fcb32a66c119d6
BLAKE2b-256 af303d34a99c92781dae01b380968ac8ba570c8ad1f72e8cea0264e0683e3fa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 298c2be313c7a4457cdcea34f130c1accfd68364c36dd79b835c742f9d6fcc3d
MD5 15a0caaafe45fee39aa7db276599402e
BLAKE2b-256 51a9cf617634b60fdafd352f592ae6adab6f2b089e82b696c379776fe4164359

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0f73b610bbd46870df8024057924ed5e6d6e44b9181fbde2c78cb46f2e830cb3
MD5 3d99c6ac6eafe09fec3e41812d93feff
BLAKE2b-256 5fdcdb84bad0dc5f8ebcd0b531368d23fd9f956ae3b343d4d1d2d3b16911f0d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b6f87573879e6dd9c6d0c0135d81b3a353633814bc40ba4a8af1b87034bfdb9
MD5 b0bc8712f21a39372a6978a32edb9215
BLAKE2b-256 e294405ed69b249fa0008614b4327992001233b4e4b7d9ae3fa8f06890d45401

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 257e2ab3e563b610698652d38d51019fbbe8d73e2d6e0926cff2c21e692e7790
MD5 85fb70d25733c52c6ccd7ee7322f4a37
BLAKE2b-256 40ee645beccefa98d2cbbc4729beb909a8ff99142ed2852182096b9bab0666fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ed322c88add28a030d7d61d86bdb1ab808818f3d1202faa66b999b16d841ee77
MD5 58ac7275ef3ef2e7b56d9582084629b1
BLAKE2b-256 2dd32382201dbca3e1f7543d5d1e20fb2f40d83f2d4bf22a337b8900661c7080

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 391a6f7a00083ae1f78e4bfdc53e5a77095361b5162156e53fbebedb6637351c
MD5 0a491b039dee4cee8a69c5260cf9b5a1
BLAKE2b-256 45e6a69574819136cb3dabe2778a44fdc8d6ca4f3a9b71baea9672988277b62b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 4d0cf3b1755fe4d1a0b26282f45b675e2fca70e149b3264e03db0b570845ae85
MD5 177d20b117e70735b33f5b7c02cd2213
BLAKE2b-256 4379b837d3a7579a42e3c4f2c0b909f89eea61a1565e06e3efb8dc9c5199e72c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8c5d10e000a378c7f61bdc0bc2255644adb2e56a5185e41562201cab2e053abb
MD5 604183159a98c5ae22a4e076d34bc8ed
BLAKE2b-256 ec069881d1e47a2f7dfb609d720b1e9a4eda8e12672cbffbd985c5c9fc3a3766

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keygen_py-0.0.1.dev1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 808d188e1934c8e87a610dfecf7ab247f82e023a60d8c9abb828c7612648f431
MD5 f3697b3f09b5755c45063aafd9b8d9ee
BLAKE2b-256 1d70aa27827ca1daa590e8ab2c6173f3962a04614b445b92b17a7ac11110f7fd

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