Skip to main content

A FastAPI-like framework for building interactive shell applications

Project description

FastShell

A FastAPI-like framework for building interactive shell applications with fish-like features including autocompletion, syntax highlighting, and history-based suggestions.

Features

  • FastAPI-like syntax - Familiar decorator-based command registration
  • Pydantic integration - Type-safe argument parsing with validation
  • Interactive shell - Fish-like experience with autocompletion and syntax highlighting
  • System command context - Persistent shell with directory tracking and environment preservation
  • Async support - Full support for async/await commands
  • Subcommands - Organize commands into logical groups
  • System commands - Optional integration with system executables
  • Flexible arguments - Support for positional, optional, and flag-based arguments

Quick Start

from fastshell import FastShell
from pydantic import BaseModel

app = FastShell(name="MyApp", description="My awesome shell app")

class Arguments(BaseModel): 
    name: str
    age: int = 18
    # Or you can put them directly in argument defintion.

# The root argument made it able to be called directly in CLI mode.
@app.command(name='hello', root=True)
def hello(args: Arguments):
    return f'Hello, {args.name}! You are {args.age} years old.'

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

Command Usage Examples

The above command can be called in multiple ways:

In interactive mode

# Positional arguments
hello John 25

# Mixed positional and flags
hello --age 25 John

# All flags
hello --name John --age 25

# Default values
hello John  # age defaults to 18

In CLI Mode

# Same with interactive, but
python3 ./main.py hello John
# This also works
python3 ./main.py John

Installation

pip3 install fastshell

Quick Start

fastshell

Features in Detail

Autocompletion

  • Command name completion
  • Argument flag completion with type information
  • Context-aware suggestions

System Command Context

  • Persistent Shell: Maintains background shell session for context preservation
  • Directory Tracking: Current directory displayed in prompt and preserved across commands
  • Environment Variables: Shell environment changes persist between commands
  • Cross-Platform: Works with cmd.exe on Windows and standard shells on Unix
  • Encoding Support: Proper GBK encoding support for Chinese characters on Windows
  • Clean Output: Intelligent filtering removes command echo and control information

Syntax Highlighting

  • Commands highlighted in blue
  • Arguments in green
  • Strings in yellow
  • Numbers in magenta
  • Flags in cyan

Argument Parsing

  • Automatic conversion between flag names and field names (--first-namefirst_name)
  • Type validation using Pydantic
  • Error handling for ambiguous arguments
  • Support for boolean flags

Subcommands

Create command groups for better organization:

file_ops = app.subinstance('file')

@file_ops.command('read')
def read_file(path: str):
    # Implementation
    pass

Usage: file read myfile.txt

System Command Context Example

# Notice the current directory in the prompt
[/home/user/project] MyApp> pwd
/home/user/project

[/home/user/project] MyApp> cd /tmp
[/tmp] MyApp> echo "test" > file.txt
[/tmp] MyApp> cat file.txt
test

[/tmp] MyApp> cd ~/project
[/home/user/project] MyApp> ls
README.md  src/  tests/

Development

Using Poetry

# Install development dependencies
poetry install

# Activate virtualenv
poetry env activate

# Build package
poetry build

Project Structure

fastshell/
├── fastshell/          # Core framework package
├── example.py          # Quick start example
└── README.md           # This file

See PROJECT_STRUCTURE.md for detailed information.

License

MIT License

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-1.0.0a2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

fastshell-1.0.0a2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file fastshell-1.0.0a2.tar.gz.

File metadata

  • Download URL: fastshell-1.0.0a2.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.9 Windows/10

File hashes

Hashes for fastshell-1.0.0a2.tar.gz
Algorithm Hash digest
SHA256 cd038319e3aa8698e1472c751c4e07c16ad58e8a8c70b686fca561f275f1ddc3
MD5 404b64f75f76a1a431f15860304eda0d
BLAKE2b-256 1da22edabd55d4d29618923b0fc3291d79e24c09c944703a53ae56882d2a760f

See more details on using hashes here.

File details

Details for the file fastshell-1.0.0a2-py3-none-any.whl.

File metadata

  • Download URL: fastshell-1.0.0a2-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.9 Windows/10

File hashes

Hashes for fastshell-1.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 b87d6756ec328c9b0f7d55c6e352189f2a40f2ef345ec4b9fb68335e3ae968c8
MD5 8c0b42ab9a2c9e7d0fb0e2b3b4acae65
BLAKE2b-256 cc1d7b5b50084d02b03ff9da6114f4cd485030eea5bd043f0f485ab76720c729

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