Skip to main content

A FastAPI-like framework for building interactive shell applications with auto-completion and type safety

Reason this release was yanked:

This stable version is unstable through. Use 1.0.0a3 instead.

Project description

FastShell

A FastAPI-like framework for building interactive shell applications with automatic completion, type conversion, and subcommands.

Features

  • 🚀 FastAPI-like decorators - Simple and intuitive API design
  • 📝 Automatic parsing - Docstrings, function names, parameters, and type annotations
  • 🔧 Auto-completion - Command and parameter completion with TUI support
  • 🌳 Subcommands - Nested command structure support
  • 🔄 Enhanced type conversion - Pydantic-powered type validation and conversion
  • 🆕 Modern Union syntax - Full support for Python 3.10+ int | str syntax
  • 🛡️ Robust validation - Better error messages and type safety
  • 🖥️ Cross-platform - Works on Windows, macOS, and Linux
  • 🎨 Rich output - Beautiful terminal output with colors and formatting

Quick Start

from typing import Union, Optional
from fastshell import FastShell

# Enable Pydantic validation (default)
app = FastShell(use_pydantic=True)

@app.command()
def hello(name: str = "World", count: int = 1):
    """Say hello to someone.
    
    Args:
        name: The name to greet
        count: Number of times to greet
    """
    for _ in range(count):
        print(f"Hello, {name}!")

@app.command()
def process(value: int | str, convert_to: Optional[str] = None):
    """Process a value with modern Union syntax.
    
    Args:
        value: Can be integer or string (Python 3.10+ syntax)
        convert_to: Optional conversion target
    """
    print(f"Processing: {value} (type: {type(value).__name__})")
    return value

@app.command()
def add(a: int, b: int, verbose: bool = False):
    """Add two numbers with optional verbose output.
    
    Args:
        a: First number
        b: Second number
        verbose: Show detailed output
    """
    result = a + b
    if verbose:
        print(f"Adding {a} and {b}...")
    print(f"{a} + {b} = {result}")

if __name__ == "__main__":
    app.run()

Installation

pip install fastshell

What's New in v2.0

🆕 Pydantic Integration

FastShell now includes Pydantic-powered type validation for enhanced type safety and better error handling:

  • Fixed Python 3.10+ Union syntax: No more 'types.UnionType' object has no attribute '__name__' errors
  • Enhanced validation: More accurate type conversion with better error messages
  • Backward compatible: Existing code works without changes
  • Configurable: Choose between Pydantic and legacy validation

Modern Type Syntax Support

# ✅ Now fully supported!
@app.command()
def modern_syntax(value: int | str, optional: str | None = None):
    """Uses Python 3.10+ Union syntax"""
    pass

# ✅ Traditional syntax still works
@app.command()
def traditional_syntax(value: Union[int, str], optional: Optional[str] = None):
    """Uses typing module syntax"""
    pass

Configuration Options

# Enable Pydantic validation (default)
app = FastShell(use_pydantic=True)

# Use legacy validation for performance
app = FastShell(use_pydantic=False)

Enhanced Error Messages

# Before: Type conversion error: invalid literal for int()
# After: Cannot convert to integer: invalid literal for int() with base 10: 'abc'

Documentation

For detailed information about Pydantic integration, see PYDANTIC_INTEGRATION.md.

Development Installation

For development, clone the repository and install in editable mode:

git clone https://github.com/originalFactor/fastshell.git
cd fastshell
pip install -e .

Development

pip install -e ".[dev]"

Testing

Run the comprehensive test suite:

python test_comprehensive_validation.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastshell-0.1.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastshell-0.1.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file fastshell-0.1.1.tar.gz.

File metadata

  • Download URL: fastshell-0.1.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for fastshell-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8cf7fc1f6e8fd0024ccaad1f00808a9127756ef74f954df5689968a56e07c8e7
MD5 56427587ba6913f07f17c7bb71e8e173
BLAKE2b-256 32310626cf35e11faf21488d0908b67785dec6983f6af93c052db158d0ff802f

See more details on using hashes here.

File details

Details for the file fastshell-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastshell-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for fastshell-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 171fe4205b7e25c01cbb73cae6b13e18e7d609fd4882a3da992abc158e187088
MD5 e904cc561dd754cdf2a3cc880be65534
BLAKE2b-256 e8e739899b841b46c32b794c405ca671755b4bc6baf458a8edbe4986d9ce5070

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page