Skip to main content

PANDA Python SDK

Private And Secure Data Access — Field-level encryption SDK for Python applications.

Overview

PANDA (Private And Secure Data Access) is a cross-language SDK for field-level encryption and masking of sensitive personal data. The Python implementation provides the same features as the PHP, Node.js, and Go versions:

  • AES-256-GCM encryption with envelope wire format
  • Masking-by-default decrypted values
  • Blind indexing for searchable encrypted fields
  • Multiple key providers: Local (.env), HashiCorp Vault, Infisical
  • CLI tool for initialization and key management
  • Framework integrations: Django, Flask, FastAPI

Installation

pip install panda-crypto-py

Quick Start

1. Initialize PANDA

panda init --token panda_demo_76d08573d453cdbdb4bf5704d13f8f54d57cd3c47c9b4be2

The wizard will guide you through:

  • Selecting a key provider (Local, Vault, or Infisical)
  • Configuring your provider
  • Generating your first encryption key

2. Use in Your Code

from panda.crypto import FieldCipher, LocalKeyProvider

# Create cipher with local keys
key_provider = LocalKeyProvider()
cipher = FieldCipher(key_provider)

# Encrypt data
envelope = cipher.encrypt("3201012501990001", kid="nik-key")

# Decrypt (returns masked value by default)
masked = cipher.decrypt(envelope)
print(masked)  # "32************01"

# Decrypt raw (audited operation)
raw = cipher.decrypt_raw(envelope)
print(raw)  # "3201012501990001"

Key Providers

Local (Environment Variables)

from panda.crypto import LocalKeyProvider

# Keys are read from PANDA_KEY_<KID> environment variables
# PANDA_KEY_NIK_KEY=<base64-encoded-32-byte-key>
key_provider = LocalKeyProvider()

HashiCorp Vault

from panda.crypto import VaultKeyProvider

key_provider = VaultKeyProvider(
    vault_url="http://localhost:8200",
    vault_token="your-token",
    mount_path="secret"
)

Infisical

from panda.crypto import InfisicalKeyProvider

key_provider = InfisicalKeyProvider(
    site_url="https://app.infisical.com",
    client_id="your-client-id",
    client_secret="your-client-secret",
    project_id="your-project-id",
    environment="dev"
)

Masking

from panda.masking import Masker

# Default: keep 2 leading, 2 trailing characters
masked = Masker.mask("3201012501990001")
# "32************01"

# Custom masking
masked = Masker.mask(
    "3201012501990001",
    keep_leading=3,
    keep_trailing=1,
    mask_char="*"
)
# "320*************1"

Blind Indexing

from panda.blind_index import BlindIndexer

# Generate blind index for searchable encryption
index = BlindIndexer.generate(
    plaintext="3201012501990001",
    key="blind-index-key",
    normalization="digits"  # or "lowercase", "trim", "raw"
)

Framework Integration

Django

# settings.py
INSTALLED_APPS = [
    ...
    'panda.integrations.django',
]

PANDA = {
    'KEY_PROVIDER_DRIVER': 'local',
    'DEFAULT_KID': 'default-key',
}

# models.py
from panda.integrations.django.fields import EncryptedField
from django.db import models

class Citizen(models.Model):
    nik = EncryptedField(kid='nik-key')
    name = models.CharField(max_length=200)

Flask

from flask import Flask
from panda.integrations.flask import PandaFlask

app = Flask(__name__)
panda = PandaFlask(app)

@app.route('/encrypt')
def encrypt():
    envelope = panda.cipher.encrypt("sensitive data", kid="my-key")
    return envelope.to_json()

FastAPI

from fastapi import FastAPI
from panda.integrations.fastapi import PandaFastAPI

app = FastAPI()
panda = PandaFastAPI(app)

@app.post("/encrypt")
def encrypt_endpoint(data: str):
    envelope = panda.cipher.encrypt(data, kid="my-key")
    return envelope.to_dict()

CLI Commands

Mode Non-Interaktif (Flags untuk CI/CD)

Semua perintah CLI dapat digunakan dalam mode non-interaktif dengan menggunakan flag. Ini sangat berguna untuk:

  • CI/CD pipelines - Otomatisasi tanpa interaksi pengguna
  • Docker containers - Inisialisasi otomatis saat container start
  • Infrastructure as Code - Integrasi dengan Terraform, Ansible, dll
  • Automated testing - Setup dan teardown otomatis

Perintah Init - Mode Non-Interaktif

# Quick init dengan Local provider (mode tercepat)
panda init --token <token> --kid default-key

# Init tanpa generate kunci pertama (untuk automation lanjutan)
panda init --token <token> --reinit

# Init dengan environment variable
export PANDA_ACCESS_TOKEN=<token>
panda init

Flag init yang tersedia:

Flag Default Deskripsi
--token <value> - PANDA access token (atau set PANDA_ACCESS_TOKEN env)
--reinit false Force re-initialization meskipun sudah ada konfigurasi

Perintah Generate - Mode Non-Interaktif

# Generate kunci dengan KID langsung (non-interactive)
panda generate my-new-key

# Generate dengan description
panda generate nik-key --description "Key for NIK encryption"

Flag generate yang tersedia:

Flag Default Deskripsi
--description <text> - Deskripsi untuk kunci

Perintah Deinit - Mode Non-Interaktif

# Hapus konfigurasi tanpa prompt
panda deinit --force

Flag deinit yang tersedia:

Flag Default Deskripsi
--force false Skip konfirmasi prompt

Tabel Lengkap Perintah CLI

# Initialize PANDA
panda init --token <your-token>

# Generate a new key
panda generate my-key

# Check status
panda status

# View configuration
panda config

# Remove PANDA from project
panda deinit --force
Perintah Memerlukan Token Mode Non-Interaktif Deskripsi
panda init --token <token> ✅ Ya ✅ (default) Inisialisasi PANDA
panda generate <kid> ❌ Tidak ✅ (default non-interactive) Generate kunci tambahan
panda status ❌ Tidak ✅ (default non-interactive) Tampilkan status konfigurasi
panda config ❌ Tidak ✅ (default non-interactive) Tampilkan detail konfigurasi lengkap
panda deinit ❌ Tidak ✅ --force Hapus konfigurasi PANDA

Envelope Format

Encrypted fields use a standardized JSON envelope:

{
  "v": 1,
  "alg": "aes-256-gcm",
  "kid": "key-identifier",
  "nonce": "<base64 12-byte IV>",
  "ciphertext": "<base64 ciphertext + 16-byte auth tag>"
}

Documentation

License

Apache License 2.0 — see LICENSE for the full text and NOTICE for attribution.

Previously MIT. Apache-2.0 is equally permissive and adds an express patent grant and a trademark clause, which MIT is silent on — it matters here because this is cryptographic software that other agencies and vendors are expected to embed in their own systems.

Support

For issues and questions:

Metadata

Release files for panda-crypto-py 0.2.7

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

Source distribution (sdist)

Source distribution for panda-crypto-py 0.2.7
File Size Uploaded
panda_crypto_py-0.2.7.tar.gz 42.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for panda-crypto-py 0.2.7
File Interpreter ABI Platform
panda_crypto_py-0.2.7-py3-none-any.whl Python 3 none any Details

Total release size: 87.8 kB

Release files / panda_crypto_py-0.2.7.tar.gz

Download URL panda_crypto_py-0.2.7.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
32e9a1f2292bbcb6d146e0d9014b0735f3f734387755cb8d50a19411f119fc99
BLAKE2b-256 checksum
How to use checksums
b2fa6d23e55e52187215402fbd2b2d097a4c6a1d9445ffdd496e79df5544290c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / panda_crypto_py-0.2.7-py3-none-any.whl

Download URL panda_crypto_py-0.2.7-py3-none-any.whl
Size 45.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92f6f6e7d8cca7f562ea107fd2abfd1d3945c627d249cf7257879d691ed9d31b
BLAKE2b-256 checksum
How to use checksums
d85b1ec15788d6a2052ca84ecc53a45a6eec46d9294ae521ae0febae63d84dcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.9

2 release files

0.2.8

2 release files

This release

0.2.7 This release

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.0

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