CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-zappa

Server-less Python Web Services for AWS Lambda and API Gateway

Overview
Eval results
Files

package-utilities.mddocs/

Package-Level Utilities

Core package functions and constants available at the top level for environment detection, version management, and system validation. These utilities provide essential functionality for Zappa's runtime environment compatibility checks.

Capabilities

Environment Detection

Detect execution environment and configure behavior accordingly.

def running_in_docker() -> bool:
    """
    Determine if zappa is running in docker.
    
    Checks environment variables to determine if Zappa is executing
    within a Docker container, which affects Python version validation
    and allows usage of any Python version.
    
    Returns:
    bool: True if running in Docker environment
    """

Usage Example:

from zappa import running_in_docker

if running_in_docker():
    print("Running in Docker - relaxed version requirements")
else:
    print("Native execution - strict version validation")

Version Management

Version Information

Current package version and supported Python versions.

__version__: str  # Current Zappa version (e.g., "0.60.2")

SUPPORTED_VERSIONS: list  # Supported Python versions
# [(3, 9), (3, 10), (3, 11), (3, 12), (3, 13)]

MINIMUM_SUPPORTED_MINOR_VERSION: int  # Minimum Python minor version (9)

Usage Examples:

from zappa import __version__, SUPPORTED_VERSIONS, MINIMUM_SUPPORTED_MINOR_VERSION
import sys

# Check current Zappa version
print(f"Zappa version: {__version__}")

# Validate Python version compatibility
current_version = sys.version_info[:2]
if current_version in SUPPORTED_VERSIONS:
    print(f"Python {current_version[0]}.{current_version[1]} is supported")
else:
    supported = [f"{v[0]}.{v[1]}" for v in SUPPORTED_VERSIONS]
    print(f"Unsupported Python version. Supported: {supported}")

# Check minimum version requirement
if sys.version_info.minor >= MINIMUM_SUPPORTED_MINOR_VERSION:
    print("Meets minimum version requirement")

Runtime Validation

The package automatically performs Python version validation on import with different behavior based on execution environment:

Native Execution

  • Enforces strict version compatibility against SUPPORTED_VERSIONS
  • Raises RuntimeError for unsupported Python versions
  • Ensures compatibility with AWS Lambda runtime requirements

Docker Execution

  • Relaxed version requirements when ZAPPA_RUNNING_IN_DOCKER=true
  • Only enforces minimum version requirement
  • Allows flexibility for containerized deployments

Environment Configuration:

# Enable Docker mode (relaxed version checking)
export ZAPPA_RUNNING_IN_DOCKER=true

# Docker mode accepts various truthy values
export ZAPPA_RUNNING_IN_DOCKER=yes
export ZAPPA_RUNNING_IN_DOCKER=1
export ZAPPA_RUNNING_IN_DOCKER=True

Constants Reference

# Package version
__version__ = "0.60.2"

# Supported Python versions for AWS Lambda
SUPPORTED_VERSIONS = [
    (3, 9),   # Python 3.9
    (3, 10),  # Python 3.10  
    (3, 11),  # Python 3.11
    (3, 12),  # Python 3.12
    (3, 13)   # Python 3.13
]

# Minimum supported minor version
MINIMUM_SUPPORTED_MINOR_VERSION = 9

Error Handling

The package performs automatic validation and raises descriptive errors:

# Example error message for unsupported version
RuntimeError: This version of Python (3.8) is not supported!
Zappa (and AWS Lambda) support the following versions of Python: ['3.9', '3.10', '3.11', '3.12', '3.13']

# Example error for Docker mode with insufficient version
RuntimeError: This version of Python (3.8) is not supported!
Zappa requires a minimum version of 3.9

Integration Examples

Version-Aware Deployment

from zappa import __version__, SUPPORTED_VERSIONS
from zappa.utilities import get_runtime_from_python_version
import sys

def check_deployment_compatibility():
    """Check if current environment is compatible for deployment."""
    current_version = sys.version_info[:2]
    
    if current_version not in SUPPORTED_VERSIONS:
        raise ValueError(f"Python {current_version[0]}.{current_version[1]} not supported for deployment")
    
    runtime = get_runtime_from_python_version()
    print(f"Using Zappa {__version__} with runtime {runtime}")
    return runtime

Docker Integration

from zappa import running_in_docker
import os

def configure_deployment_environment():
    """Configure deployment based on execution environment."""
    if running_in_docker():
        # Docker-specific configuration
        print("Configuring for Docker deployment")
        os.environ.setdefault('ZAPPA_DOCKER_BUILD', 'true')
        return 'docker'
    else:
        # Native environment configuration  
        print("Configuring for native deployment")
        return 'native'

CI/CD Pipeline Integration

#!/bin/bash
# CI/CD script with Docker support

if [[ "$USE_DOCKER" == "true" ]]; then
    export ZAPPA_RUNNING_IN_DOCKER=true
    docker run --rm -v $(pwd):/app -w /app python:3.11 \
        pip install zappa && zappa deploy
else
    # Native deployment
    zappa deploy
fi

Install with Tessl CLI

npx tessl i tessl/pypi-zappa

docs

async-tasks.md

cli-operations.md

core-deployment.md

index.md

package-utilities.md

request-processing.md

ssl-management.md

utilities.md

wsgi-processing.md

tile.json