Skip to main content

fastapi-license

Enterprise hardware-bound license system for FastAPI applications.
Distribusi binary terobfuskasi via PyArmor v8+ BCC mode, dengan CLI berbasis Click + Rich dan integrasi FastAPI Lifespan & Middleware.


Instalasi

pip install fastapi-license

Alur Kerja

1. Client: Ambil Hardware Fingerprint (Server Klien)

fastapi-license probe --output fingerprint.json

2. Developer: Generate Lisensi

fastapi-license gen \
  --fingerprint fingerprint.json \
  --expiry 2027-12-31 \
  --features "analytics,pdf_export,billing" \
  --private-key private.pem \
  --output license.lic

3. Developer: Build & Obfuskasi Kode FastAPI

fastapi-license build --src ./my_app --dist ./dist_protected --bcc

4. Admin: Inspeksi Lisensi

fastapi-license inspect --license license.lic --public-key public.pem

Integrasi FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI, Depends
from fastapi_license import LicenseManager, LicenseGuardMiddleware, require_feature

license_manager = LicenseManager(
    license_path="license.lic",
    public_key_path="public.pem"
)

@asynccontextmanager
async def lifespan(app: FastAPI):
    license_manager.verify_on_startup()
    yield

app = FastAPI(title="Protected API", lifespan=lifespan)
app.add_middleware(LicenseGuardMiddleware, manager=license_manager)

@app.get("/api/analytics", dependencies=[Depends(require_feature("analytics"))])
async def analytics():
    return {"data": "Analytics stream"}

Generate Keypair

from fastapi_license.core.crypto import CryptoEngine

engine = CryptoEngine()
private_pem, public_pem = engine.generate_keypair(algorithm="ed25519")

with open("private.pem", "wb") as f:
    f.write(private_pem)
with open("public.pem", "wb") as f:
    f.write(public_pem)

Security Architecture

  • Hardware Binding: CPU ID + Motherboard UUID + Root Disk Serial + Primary MAC → SHA-256
  • Cryptography: Ed25519 (default) / RSA-4096 asymmetric signature
  • Obfuscation: PyArmor v8+ BCC Mode → native C binary (.so / .pyd)
  • Fail-Closed: Semua error lisensi menyebabkan sys.exit(1) sebelum server bind port
  • Clock Anti-Tamper: Monotonic clock + heartbeat timestamp comparison

Exception Hierarchy

Exception Trigger
LicenseNotFoundError File license.lic tidak ditemukan
TamperDetectedError Signature cryptographic tidak valid
HardwareMismatchError Hardware ID server tidak cocok
LicenseExpiredError Tanggal kedaluwarsa terlewat
ClockTamperError Manipulasi waktu sistem terdeteksi

Metadata

Release files for fastapi-license 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-license 1.0.0
File Size Uploaded
fastapi_license-1.0.0.tar.gz 36.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-license 1.0.0
File Interpreter ABI Platform
fastapi_license-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 62.1 kB

Release files / fastapi_license-1.0.0.tar.gz

Download URL fastapi_license-1.0.0.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4d0002d7049afbdcf1ae853024b02a08df96f5fcd376e6572cfac1b2d3df27fd
BLAKE2b-256 checksum
How to use checksums
4f47c4e0207e37cf28539bd3137f1713bf259316fcba314f09fe8ea6cfa769ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / fastapi_license-1.0.0-py3-none-any.whl

Download URL fastapi_license-1.0.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a6f2fb8572ee7eb01ce7c6f1cd2f68cb508d2f8ff21b28765c60779aacea55
BLAKE2b-256 checksum
How to use checksums
3a4e4522ff5cdda0c241981b5231c0ae73289df3cffcf7bc93df1388eb56967a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page