Overview
What MagicLock protects, the two protection tiers, and the concepts that show up everywhere else in these docs.
MagicLock is a command-line tool and Python SDK that encrypts your Python source code and AI models, gates them behind a signed license, and checks that license fully offline every time your software runs. You install one package, run one command, and ship.
The mental model
Everything in MagicLock comes down to two independent questions: what you're protecting, and how strong the protection needs to be.
| What it protects | Output | Strength | |
|---|---|---|---|
| Convenience tier | Python source (.py) | .pya — an encrypted, gated container the import system understands | Good — stops casual copying; the decrypted bytecode exists in memory while running |
| Compiled tier | Python source, compiled | Native .so / .pyd, or a standalone app directory | Strong — no plaintext Python ships, and the license gate is auto-inserted into every compiled module, not concentrated in one place an attacker could find and patch out |
| Model/resource protection | Models, weights, any binary asset | .enc — an encrypted envelope | Applies to either tier; the plaintext only ever exists in memory |
You can use the convenience tier to get protection running in minutes, then move to the compiled tier later without changing how your code is written — the compiled tier's gate is inserted automatically, with no decorator or manual bootstrap() call to add.
Core concepts
A handful of ideas recur throughout these docs:
- License — a signed grant issued to your account: what capabilities you're allowed to use, and until when. Issued and verified without you ever handling a key file directly.
- Device-bound (node-locked) — by default, a license — and anything encrypted with it — is tied to the specific machine it was activated on. Copy the encrypted file to another machine and it won't decrypt there.
- Activation — the one-time step that provisions a machine under your account. It's folded into your first
protect/buildcall, so you'll rarely run it by hand — see Account & Activation. - Capability — a named permission a license can grant (code protection, model encryption, and so on). The runtime gate and
open_model()each check for the capability they need. - Offline grace — encrypting checks in with the license server; if you're briefly offline, a grace window keeps you working. Decrypting never needs a network at all, ever.
- Expiry — an optional, separate control on the encrypted artifact itself — independent of your license — that stops it from decrypting after a date or duration.
60-second quickstart
pip install magiclock
# First run: signs you in (opens a browser) and activates this machine,
# then encrypts. Every encrypt after that is instant and non-interactive.
magiclock protect app.py # -> app.pya
# Runs fully offline: no login, no network, ever.
magiclock run app.pyaWhere to go next
- Install — requirements, the optional compiled-tier extra, upgrading.
- Encrypting Code —
protect/run, expiry, two-factor lock, portable artifacts. - Encrypting Models & Resources —
protect-model,bootstrap(),open_model(). - Compiled Build —
magiclock build, the automatic per-module gate, what you can ship. - Account & Activation — zero-config activation, CI, offline behavior, revocation.
- CLI Reference and Python API Reference — every command, flag, and function signature.
- Security Model — what the runtime gate actually checks, and its honest limits.