What a key can and cannot do for a script
A compiled desktop app hides its logic behind a binary. A script does not. The buyer opens the file, reads the license check and deletes it. Obfuscation slows this only a little and makes bug reports hard to read; see code obfuscation.
So decide what you are selling. Typical answers that a key can enforce:
- Updates and fixes. The maintained version, delivered to valid keys. When an API a script depends on changes, the buyer needs your fix.
- Support. Answers for key holders.
- New scripts. A growing library behind a subscription.
- A hosted piece. A service the script calls, which checks the key on your server.
What a key cannot do is stop a determined person from running the copy they bought. Treat the check as a way to keep casual sharing from becoming normal. The piracy article takes this view in more detail.
A check that works under cron
A script often runs unattended: from cron, a scheduled task, CI or a launcher. It has no screen to show an error, so use exit codes the caller can act on. This Python version was run against the public demo key: it exits 0 for a valid license, 2 for an unknown key and 3 when the check could not be completed.
#!/usr/bin/env python3
"""Exit 0 when the license is valid, 2 when it is not, 3 when Clavem cannot be reached."""
import json
import os
import sys
import urllib.error
import urllib.parse
import urllib.request
KEY = os.environ.get("MYTOOL_LICENSE_KEY", "")
def check(key: str) -> int:
request = urllib.request.Request(
"https://clavem.io/v1/licenses/validate",
data=urllib.parse.urlencode({"license_key": key}).encode(),
headers={"User-Agent": "mytool/1.0"}, # the default Python agent string can be blocked
)
try:
with urllib.request.urlopen(request, timeout=8) as response:
body = json.load(response)
except urllib.error.HTTPError as error:
return 2 if error.code == 404 else 3 # 404: unknown key. 429, 5xx: could not check
except (urllib.error.URLError, TimeoutError):
return 3
return 0 if body.get("valid") else 2
if __name__ == "__main__":
sys.exit(check(KEY))
A known key always answers 200, whether or not it is valid, so read valid. An expired or disabled license answers 200 with valid: false. An unknown key is a 404 with license_key not found.
What to do with exit code 3 is your decision. For a nightly job, “could not check” should usually mean “run anyway, and try again next time”, otherwise a Wi-Fi blip stops an automation. Cache the last good result in a file with a time, and accept it for a few days. For a sturdier version, verify Clavem’s signed token with the public key; see offline verification and the Python guide.
Validate or activate
A script can use the License API two ways, and they count devices differently.
| Approach | Calls | Device limit | Best for |
|---|---|---|---|
| Validate only | validate with the key |
None enforced: any machine with the key passes | Scripts that run in containers, CI and ephemeral servers |
Activate once, validate with instance_id |
activate on first run, then validate with the instance id |
Enforced: each machine takes a seat | Scripts a person installs on their own machines |
Validate-only is simple and cannot limit copies. If a key is shared widely, you will see it in your sales rather than in the device count. Activation limits machines, at the cost of a first-run step and a stored instance id. Pick the one that matches your price. For a cheap script, validate-only avoids support mail. For a pricier toolkit, activation protects revenue. A fingerprint on activation makes re-installs free for the customer; see the API reference.
Keep the rate limit in mind: 60 requests a minute per key and 120 per IP address. A cron job once a minute on one machine is fine; a job that checks once per file processed is not. Check once per run.
Delivering and updating a script
Upload the script as a release file with no platform label, which Clavem treats as universal and offers to every platform. For a script with a Windows and a Unix variant, label them. The script can ask for updates itself: GET /v1/releases/:productId/latest with the key in the X-License-Key header returns the version and, for a valid key, a signed download link that lasts an hour. A key that is expired or disabled still learns that an update exists, so the script can say “renew to update”. See releases and downloads.
Script files are small, so even the free plan’s 1 GB of storage holds many versions.
Recommended setup
| Setting | Suggested value | Why |
|---|---|---|
| License type | One-time with a year of updates, or an annual subscription | Scripts need maintenance when the tools they drive change |
| Device limit | 3, or no activation at all | Laptop, server and a spare |
| Trial | A free script with limits, or the first N runs | A readable script makes a time-based trial easy to remove |
| Updates | The script checks the releases endpoint | Buyers get fixes without email |
Clavem does not offer a perpetual license with a time-limited updates window as one setting. Sell a perpetual license and give updates to every valid key, or sell a subscription.
Doing this with Clavem
Create a product, connect Stripe, map the price. A buyer receives a key by email and an order page with the script. The first lines of the script read the key from an environment variable or a config file and call validate. The Python guide has the full flow with a stored token, and the CLI tools page has a shell version.
Guides to follow
- License key validation in Python
- Offline license verification in Python
- Software updates in Python
- License key validation in Node.js
Questions
Can I stop people sharing a script they can read?
Not by code alone. Anyone who can run a script can read it, and removing a check is a one-line edit. Make the paid version better than a copy: updates, fixes, support and new scripts, delivered to keys that are valid.
Why does my Python script get a 403 from the License API?
Check the User-Agent header. Python's default urllib agent string can be refused by services behind bot protection. Send your own, such as mytool/1.0.