🐍Python SDK

πŸ“˜ Introduction

DevPayr Python SDK is the official framework-agnostic client for integrating with DevPayr β€” a modern licensing, domain enforcement, and injectable delivery system for SaaS and software products.

This SDK enables Python developers to:

  • βœ… Validate license keys securely (with or without payment enforcement)

  • πŸ” Stream and decrypt encrypted injectables from the DevPayr backend

  • 🌍 Enforce domain/subdomain access using DevPayr's project-bound policies

  • βš™οΈ Manage projects, licenses, domains, API keys, and more

  • πŸ” Handle automatic revalidation or failover behavior for expired or revoked licenses

It is designed to work with any Python environment, including:

  • 🐍 Flask, Django, FastAPI, or any other Python web framework

  • 🧩 CLI scripts, background jobs, or system-level services

  • 🎯 Desktop software or headless backend processors

You remain fully in control of what happens when a license is invalid β€” show a modal, redirect users, log silently, or define a custom error handler.

Get started in minutes and enforce your license policies with confidence.

πŸ“¦ Installation

You can install the DevPayr Python SDK using either pip or by cloning the repository.

If you're using PyPi (when published):

πŸ”§ Option 2: Install via source (for local development)

  1. Clone the repository:

  1. Install in editable mode:

This allows you to edit the SDK source locally and test changes instantly without reinstalling.

πŸ“ Optional Dependencies

If you want to enable encryption or validation features, the SDK automatically includes:

  • requests

  • cryptography

To install these manually (if needed):

You're now ready to initialize DevPayr.bootstrap() and begin validating license keys or streaming injectables.

πŸš€ Getting Started

This section walks you through how to quickly set up and use the DevPayr SDK in your Python application.

πŸ” Basic Usage

⚠️ Note: If using injectables, you must specify secret and injectablesPath. In fact, secret is always required

πŸ§ͺ Validate License Before Execution

When using license validation (license key), the SDK will automatically:

  • Contact DevPayr’s API

  • Validate payment or subscription

  • Optionally fetch and decrypt injectables

  • Trigger a failure behavior (modal, redirect, log, or silent)

πŸ›  Behavior on Invalid License

You can control what happens when the license is invalid via:

Mode
Description

modal

Displays a styled HTML page to block app usage (default)

redirect

Opens a browser tab to a custom upgrade/payment URL

log

Prints an error message to stderr

silent

Does nothing (silent failure β€” use with caution)

πŸ“ Injectables Handling

If injectables = True, the SDK will:

  • Stream encrypted files for that license

  • Decrypt and verify using secret

  • Write them to injectablesPath

  • Support modes like append, prepend, replace

You can also override the default handler via a custom InjectableProcessor.


Now that you're set up, you can start accessing DevPayr's API through built-in service classes like:

βš™οΈ Usage Examples

Here are some common examples of how to use the DevPayr Python SDK:


βœ… Basic License Validation

Alternatively, if you want more control:

πŸš€ Project Creation

Or manually:

πŸ”‘ License Management

Or:

🌐 Domain Management

πŸ“¦ Injectable Streaming

You can also fetch them manually:

πŸ” Runtime Validation & Injectables

The DevPayr Python SDK supports runtime license validation and secure injectable management. When configured, the SDK automatically validates your license and handles injectables securely.

πŸ§ͺ How It Works

  1. License Validation When DevPayr.bootstrap() is called with a license and secret, the SDK makes a call to the DevPayr backend to validate the license using your secret.

  2. Injectable Fetching If injectables=True, the SDK will request the encrypted injectables associated with your license.

  3. Decryption & Signature Verification Each injectable is:

    • Decrypted using AES-256-CBC with the secret

    • Verified using HMAC-SHA256 signature

  4. Writing Injectables If handleInjectables=True, verified injectables are written to your filesystem using the target_path and mode (append, prepend, replace).


πŸ”’ Example Configuration

πŸ’‘ Notes

  • All written files are placed in injectablesPath (defaults to current directory).

  • Signature verification ensures content has not been tampered with.

  • You can set injectablesVerify=False to skip HMAC verification (not recommended).

🧰 Custom Injectable Processor

You can define your own custom injectable processor by implementing the InjectableProcessorInterface. This allows you to take full control of how injectables are decrypted, verified, and saved (e.g., storing in a DB, writing to disk, or injecting into memory).

To use a custom processor, simply pass it via the injectablesProcessor key in the DevPayr.bootstrap() config.

πŸ”§ Example: Custom Processor Implementation

βš™οΈ Using the Processor

βœ… With this setup, your injectables will be processed using your custom logic instead of the default built-in handler.

❌ Failure Modes & Behavior

When the SDK fails to validate a license (e.g., expired, revoked, or invalid), the invalidBehavior config key determines how the SDK should respond. This is useful for preventing unauthorized access while offering flexible handling strategies.


πŸ› οΈ Supported invalidBehavior Options

Mode
Description

modal

Prints a styled HTML message to the screen (for CLI or frontend display). This is the default behavior.

redirect

Opens the provided redirectUrl in the browser and exits. Useful in desktop or GUI apps.

log

Logs the error message to stderr without exiting the program.

silent

Suppresses all error output and continues execution (not recommended).


🧾 Example

🧩 Custom Error Message or View

You can customize the modal output by using:

  • customInvalidMessage: A string to override the default error message.

  • customInvalidView: A path to your own .html file to render instead of the default modal.

πŸ“Œ Note: If using modal, the SDK will attempt to render a default HTML view (resources/unlicensed.html) if no custom view is provided.

πŸ§ͺ Testing

The DevPayr Python SDK includes direct test scripts within the tests/ directory for validating various components such as license validation, injectables handling, encryption, and service APIs.

These tests can be run individually without any test runner like pytest β€” just using standard Python.


βœ… Running Tests

To run a test file, use:

Or any other test file in the tests/ folder, for example:

Last updated