CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python-gnupg

A wrapper for the Gnu Privacy Guard (GPG or GnuPG)

Pending
Overview
Eval results
Files

gpg-instance.mddocs/

GPG Instance Management

Core GPG instance creation and configuration for establishing connections to the GPG binary and setting up the cryptographic environment.

Capabilities

GPG Instance Creation

Creates a GPG instance with comprehensive configuration options for binary location, keyring paths, and environment settings.

class GPG:
    def __init__(self, gpgbinary='gpg', gnupghome=None, verbose=False, 
                 use_agent=False, keyring=None, options=None, 
                 secret_keyring=None, env=None):
        """
        Initialize a GPG process wrapper.

        Parameters:
        - gpgbinary (str): Path to the GPG binary to use (default: 'gpg')
        - gnupghome (str): Path to GPG home directory for keyrings
        - verbose (bool): Enable verbose output
        - use_agent (bool): Use GPG agent for passphrase handling
        - keyring (str|list): Alternative keyring file(s) to use
        - options (list): Additional command-line options for GPG
        - secret_keyring (str|list): Alternative secret keyring file(s)
        - env (dict): Environment variables for GPG subprocess
        """

Instance Properties

Properties and attributes available on GPG instances for configuration and introspection.

class GPG:
    # Configuration properties
    gpgbinary: str          # Path to GPG binary
    gnupghome: str          # GPG home directory path
    keyring: list           # List of keyring files
    secret_keyring: list    # List of secret keyring files
    verbose: bool           # Verbose output flag
    use_agent: bool         # GPG agent usage flag
    options: list           # Additional GPG options
    env: dict               # Environment variables
    encoding: str           # Character encoding (default: 'latin-1')
    
    # Runtime properties
    version: tuple          # GPG version information
    buffer_size: int        # I/O buffer size
    decode_errors: str      # Error handling strategy
    on_data: callable       # Data callback function

Utility Methods

Utility methods for validation and argument construction.

def make_args(self, args, passphrase):
    """
    Construct command line arguments for GPG operations.
    
    Parameters:
    - args (list): Base arguments for the operation
    - passphrase (str): Passphrase to include if needed
    
    Returns:
    list: Complete argument list for GPG subprocess
    """

def is_valid_file(self, fileobj):
    """
    Check if object is a valid file-like object.
    
    Parameters:
    - fileobj: Object to validate
    
    Returns:
    bool: True if object is file-like
    """

def is_valid_passphrase(self, passphrase):
    """
    Validate passphrase format (no newlines allowed).
    
    Parameters:
    - passphrase (str): Passphrase to validate
    
    Returns:
    bool: True if passphrase is valid
    """

def set_output_without_confirmation(self, args, output):
    """
    Configure output file handling to avoid confirmation prompts.
    
    Parameters:
    - args (list): Command arguments to modify
    - output (str): Output file path
    """

Usage Examples

Basic Instance Creation

import gnupg

# Default configuration
gpg = gnupg.GPG()

# Custom GPG binary location
gpg = gnupg.GPG(gpgbinary='/usr/local/bin/gpg2')

# Custom GPG home directory
gpg = gnupg.GPG(gnupghome='/home/user/.gnupg')

# Multiple configuration options
gpg = gnupg.GPG(
    gpgbinary='/usr/bin/gpg',
    gnupghome='/path/to/gnupg/home',
    verbose=True,
    use_agent=True,
    options=['--trust-model', 'always']
)

Alternative Keyring Configuration

# Single alternative keyring
gpg = gnupg.GPG(keyring='/path/to/keyring.gpg')

# Multiple keyrings
gpg = gnupg.GPG(keyring=[
    '/path/to/public.gpg',
    '/path/to/additional.gpg'
])

# Custom secret keyring
gpg = gnupg.GPG(
    keyring='/path/to/public.gpg',
    secret_keyring='/path/to/secret.gpg'
)

Environment and Options

# Custom environment variables
gpg = gnupg.GPG(env={
    'GNUPGHOME': '/tmp/gnupg',
    'GPG_TTY': '/dev/tty'
})

# Additional GPG options
gpg = gnupg.GPG(options=[
    '--trust-model', 'always',
    '--cipher-algo', 'AES256',
    '--digest-algo', 'SHA256'
])

# Data callback for progress monitoring
def data_callback(data):
    print(f"Processing: {len(data)} bytes")

gpg = gnupg.GPG()
gpg.on_data = data_callback

Install with Tessl CLI

npx tessl i tessl/pypi-python-gnupg

docs

encryption-decryption.md

gpg-instance.md

index.md

key-discovery.md

key-management.md

keyserver-operations.md

signing-verification.md

tile.json