CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-localstack-core

The core library and runtime of LocalStack - a comprehensive AWS cloud emulator for local development and testing.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

LocalStack

A fully functional local AWS cloud stack that emulates AWS services for local development and testing. LocalStack provides a comprehensive AWS cloud emulator running in a single container, supporting 45+ AWS services with high fidelity APIs, making it ideal for developing and testing cloud applications without the cost and complexity of real AWS infrastructure.

Package Information

  • Package Name: localstack-core
  • Language: Python
  • Installation: pip install localstack-core
  • Requirements: Python >=3.9

Core Imports

For CLI operations:

from localstack.cli.main import main

For configuration access:

from localstack import config
from localstack.config import Directories

For AWS client connectivity:

from localstack.aws.connect import connect_to

Basic Usage

# Starting LocalStack programmatically
from localstack.cli.main import main
import sys

# Start LocalStack in Docker (equivalent to 'localstack start')
sys.argv = ['localstack', 'start', '--docker']
main()

# Using LocalStack's AWS client factory
from localstack.aws.connect import connect_to
import boto3

# Connect to LocalStack services using the factory
s3_client = connect_to().s3
dynamodb = connect_to().dynamodb

# Or use standard boto3 with LocalStack endpoint
s3 = boto3.client(
    's3',
    endpoint_url='http://localhost:4566',
    aws_access_key_id='test',
    aws_secret_access_key='test',
    region_name='us-east-1'
)

# Create a bucket and upload a file
s3.create_bucket(Bucket='my-test-bucket')
s3.put_object(Bucket='my-test-bucket', Key='test.txt', Body=b'Hello LocalStack!')

# List buckets to verify
response = s3.list_buckets()
print(f"Buckets: {[b['Name'] for b in response['Buckets']]}")

CLI usage:

# Start LocalStack in Docker
localstack start

# Start with custom configuration
localstack start --docker -e DEBUG=1 -e SERVICES=s3,dynamodb

# Check service status
localstack status services

# View logs
localstack logs -f

# Stop LocalStack
localstack stop

Architecture

LocalStack follows a modular, plugin-based architecture:

  • Container Runtime: Runs in Docker with configurable networking and volumes
  • Gateway System: Routes AWS API requests to appropriate service providers
  • Service Providers: Pluggable implementations of AWS services via the ASF (AWS Service Framework)
  • Plugin System: Extensible architecture for custom services and CLI commands
  • Configuration System: Environment-based configuration with profile support
  • Testing Framework: Integrated pytest fixtures and snapshot testing capabilities

The AWS Service Framework (ASF) enables high-fidelity AWS API emulation by using AWS service specifications to generate skeleton services that can be extended with custom implementations.

Capabilities

CLI Commands

Comprehensive command-line interface for managing LocalStack lifecycle, configuration, and package management.

# Entry point function
def main() -> None:
    """Main CLI entry point with profile and environment loading"""

# Core lifecycle commands  
localstack start [--docker|--host] [--detached] [options...]
localstack stop
localstack restart
localstack logs [-f] [-n N]
localstack wait [-t N]
localstack ssh

CLI Commands

Configuration System

Environment-based configuration management with profiles, directory management, and platform detection.

# Configuration functions
def load_environment(profiles: str = None, env=os.environ) -> list[str]:
    """Load configuration from profiles and environment variables"""

def parse_boolean_env(env_var_name: str) -> bool | None:
    """Parse boolean environment variables with LocalStack conventions"""

def is_env_true(env_var_name: str) -> bool:
    """Check if environment variable is set to true"""

# Directory management
class Directories:
    static_libs: str
    var_libs: str  
    cache: str
    tmp: str
    data: str
    config: str
    logs: str
    
    @classmethod
    def defaults() -> 'Directories':
        """Get default directory paths"""
        
    def mkdirs(self) -> None:
        """Create all directories"""

Configuration

AWS Services

Emulation of 45+ AWS services through a pluggable provider system with high-fidelity APIs.

# Service management
class ServiceManager:
    def get_service(self, name: str) -> Service | None:
        """Get service instance by name"""
        
    def is_running(self, name: str) -> bool:
        """Check if service is running"""
        
    def get_states(self) -> dict[str, ServiceState]:
        """Get status of all services"""

# Service provider decorator
def aws_provider(
    api: str = None, 
    name: str = "default", 
    should_load: callable = None
) -> callable:
    """Decorator for registering AWS service providers"""

# Service states
class ServiceState(Enum):
    UNKNOWN = "unknown"
    AVAILABLE = "available"
    RUNNING = "running" 
    ERROR = "error"

AWS Services

Utilities and Testing

Comprehensive utility modules for file operations, networking, async operations, and integrated testing framework.

# File utilities
def save_file(file_path: str, content: str, append: bool = False) -> None:
    """Save content to file"""

def load_file(file_path: str, default=None, mode: str = None) -> str:
    """Load file content with optional default"""

# Network utilities  
def get_free_tcp_port() -> int:
    """Get available TCP port"""

def is_port_open(port_or_url: str | int, http_path: str = None) -> bool:
    """Check if port is open"""

# Async utilities
async def run_sync(func: callable, *args, **kwargs):
    """Run synchronous function in async context"""

def run_async(coro, loop=None):
    """Run async coroutine in sync context"""

Utilities & Testing

Plugins and Extensions

Extensible plugin system for custom CLI commands, service providers, and runtime extensions.

# CLI plugin system
class LocalstackCliPlugin:
    namespace: str = "localstack.plugins.cli"
    
    def attach(self, cli) -> None:
        """Attach commands to CLI"""

# Service plugins
class ServicePlugin:
    service: str
    api: str
    
    def create_service(self) -> Service:
        """Create service instance"""

# Plugin loading
def load_cli_plugins(cli) -> None:
    """Load all CLI plugins from namespace"""

Plugins & Extensions

Types

class Service:
    """LocalStack service instance"""
    
    def __init__(
        self, 
        name: str, 
        start: callable = None, 
        check: callable = None, 
        skeleton=None, 
        active: bool = False, 
        stop: callable = None
    ): ...
    
    def start(self, asynchronous: bool = True) -> None:
        """Start the service"""
        
    def stop(self) -> None:
        """Stop the service"""
        
    def check(self, expect_shutdown: bool = False, print_error: bool = False) -> bool:
        """Check service health"""
        
    def is_enabled(self) -> bool:
        """Check if service is enabled"""

class ServiceState(Enum):
    """Service lifecycle states"""
    UNKNOWN = "unknown"
    AVAILABLE = "available"
    DISABLED = "disabled" 
    STARTING = "starting"
    RUNNING = "running"
    STOPPING = "stopping"
    STOPPED = "stopped"
    ERROR = "error"
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/localstack-core@4.7.x
Publish Source
CLI
Badge
tessl/pypi-localstack-core badge