Simple and extensible admin interface framework for Flask
86
Quality
Pending
Does it follow best practices?
Impact
86%
1.30xAverage score across 10 eval scenarios
Redis command-line interface integration providing an interactive Redis console within Flask-Admin. This allows administrators to execute Redis commands directly through the web interface.
Interactive Redis console that provides a web-based interface for executing Redis commands with safety checks and formatted output.
from flask_admin.contrib.rediscli import RedisCli
class RedisCli(BaseView):
def __init__(
self,
redis,
name=None,
category=None,
endpoint=None,
url=None
):
"""
Redis CLI view for web-based Redis command execution.
Parameters:
- redis: Redis connection object
- name: View name (optional)
- category: View category for menu organization
- endpoint: Base endpoint name
- url: Base URL path
"""Built-in command parsing, validation, and execution system with error handling and result formatting.
def _execute_command(self, name, args):
"""
Execute Redis command with validation and error handling.
Parameters:
- name: str, Redis command name
- args: tuple, Command arguments
Returns:
Formatted HTML response with command results
"""
def _parse_cmd(self, cmd):
"""
Parse command string using shell-like syntax.
Parameters:
- cmd: str, Raw command string to parse
Returns:
tuple: Parsed command parts
"""Command filtering and remapping system to prevent dangerous operations and provide user-friendly aliases.
# Command configuration attributes
remapped_commands = {
'del': 'delete'
}
excluded_commands = set(('pubsub', 'set_response_callback', 'from_url'))Interactive help system providing command documentation and usage information.
def _cmd_help(self, *args):
"""
Built-in help command implementation.
Parameters:
- args: Optional command name for specific help
Returns:
Help text for specified command or general help
"""Comprehensive error handling with user-friendly error messages and exception management.
class CommandError(Exception):
"""Redis CLI command error exception."""
def _error(self, msg):
"""
Format error message as HTML response.
Parameters:
- msg: str, Error message to format
Returns:
HTML formatted error response
"""from flask import Flask
from flask_admin import Admin
from flask_admin.contrib.rediscli import RedisCli
import redis
app = Flask(__name__)
admin = Admin(app)
# Create Redis connection
redis_client = redis.Redis(host='localhost', port=6379, db=0)
# Add Redis CLI to admin interface
admin.add_view(RedisCli(
redis_client,
name='Redis Console',
category='Tools'
))import redis
from flask_admin.contrib.rediscli import RedisCli
# Redis with authentication
redis_client = redis.Redis(
host='localhost',
port=6379,
password='your-password',
decode_responses=True
)
class SecureRedisCli(RedisCli):
def is_accessible(self):
# Add your security checks here
return current_user.is_admin()
admin.add_view(SecureRedisCli(
redis_client,
name='Redis Admin',
category='Database Tools'
))Install with Tessl CLI
npx tessl i tessl/pypi-flask-admindocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10