Skip to main content

Python SDK for GrebKey license key validation, see grebkey.efraim.us

Project description

GrebKey

Python SDK for validating GrebKey license keys inside your application. It works completely remotely and makes it easy to implement features like machine activation, expiration, and offline grace periods. The SDK handles caching and retries so your users stay licensed even if the API is temporarily unreachable. This sdk is designed to be simple and secure, with no sensitive information stored on the client side. It identifies machines using stable OS-level identifiers without relying on hardware serial numbers or MAC addresses, making it robust across different environments and user permissions.

Install

pip install grebkey

Quickstart

from grebkey import GrebKeyClient, GrebKeyError

client = GrebKeyClient(
    api_url="https://grebkeyapi.efraim.us",
    product_id="prod_abc123",
)

try:
    result = client.validate("GREB-XXXX-XXXX-XXXX-XXXX")
except GrebKeyError:
    print("Could not verify license.")
    exit(1)

if result.valid and result.machine_activated:
    print("Licensed!")
else:
    print(f"Not licensed: {result.reason}")

Configuration

Parameter Type Default Description
api_url str required Base URL of your GrebKey API
product_id str None Restrict validation to a specific product
cache_ttl int 3600 Seconds before re-validating over the network
grace_period int 86400 Seconds the app keeps working if the API is unreachable
cache_dir str ~/.grebkey/cache Directory for the local cache file
timeout int 10 HTTP request timeout in seconds

Caching and offline behavior

On every validate() call:

  1. If a cached result exists and is younger than cache_ttl, it's returned immediately (no network call).
  2. If the cache is stale, the SDK hits the API and updates the cache.
  3. If the API is unreachable and a cached result exists within the grace_period, that cached result is returned with result.from_cache = True.
  4. If the API is unreachable and no valid cache exists (or grace period expired), GrebKeyNetworkError is raised.

Cache files are stored at ~/.grebkey/cache/ with permissions 0600 (owner read/write only). The license key itself is never stored — only a hash of it is used as the filename.

Machine fingerprinting

The SDK automatically identifies the current machine by hashing together stable OS-level identifiers:

  • Linux: /etc/machine-id
  • macOS: IOPlatformUUID from ioreg
  • Windows: MachineGuid from the registry

Hostname and username are included as fallback signals. The result is a SHA-256 hex string that stays stable across reboots and app updates without requiring admin privileges.

Access it directly with client.get_fingerprint().

Error handling

from grebkey import GrebKeyError, GrebKeyNetworkError, GrebKeyAPIError

try:
    result = client.validate(key)
except GrebKeyNetworkError:
    # API unreachable and no valid cache / grace period expired
    pass
except GrebKeyAPIError as e:
    # API returned 4xx or 5xx
    print(e.status_code, e.message)
except GrebKeyError:
    # Catch-all for any other GrebKey error
    pass

Full API reference

GrebKeyClient

client.validate(key) -> ValidationResult

Check whether the license key is valid and this machine is authorized.

result.valid                  # bool
result.reason                 # str | None — "invalid_key", "expired", "suspended", "revoked", "product_mismatch"
result.key_id                 # str
result.product_id             # str
result.metadata               # dict
result.max_activations        # int
result.current_activations    # int
result.remaining_activations  # int
result.machine_activated      # bool — is THIS machine activated?
result.expires_at             # str | None — ISO timestamp
result.from_cache             # bool — served from local cache?

client.activate(key, api_key=None, label=None) -> ActivationResult

Register this machine against the license key.

Warning: The api_key parameter requires a gk_live_ secret key. Never embed this in client software shipped to end users. Use this method server-side only, or proxy through your own backend.

activation.id           # activation ID
activation.fingerprint  # machine fingerprint used

client.deactivate(key, api_key=None)

Remove this machine's activation. Same auth considerations as activate().

client.get_fingerprint() -> str

Return the stable machine fingerprint (SHA-256 hex string) for the current machine.


GrebKey docs (Not Done Yet!) · Dashboard

Project details


Download files

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

Source Distribution

grebkey-0.1.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grebkey-0.1.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file grebkey-0.1.2.tar.gz.

File metadata

  • Download URL: grebkey-0.1.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for grebkey-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cf21e5648523060725664551a368b3c54fd30ba32c9d77a7e6a9be2db5215348
MD5 b72c85abc75f34b5c226eede5be9008a
BLAKE2b-256 5f343d4891ef77dc569e0cd3a8facbd21bb954c989904e125ae87b73edd7e1e3

See more details on using hashes here.

File details

Details for the file grebkey-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: grebkey-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for grebkey-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 933530376239b97d571d5d6eada8e25375e65badbaa9193864e2706a2469234a
MD5 75d459fb0ecad7badcba9eae02944fe5
BLAKE2b-256 5f54a22a614fb4fb1a2d85b91cc478ad40ff6459cd2433a9d068c4d9ba5c35a2

See more details on using hashes here.

Supported by

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