Slash commands and autocompletions
Project description
Slashed
A Python library for implementing slash commands with rich autocompletion support.
Features
- Simple command registration system
- Rich autocompletion support with multiple providers
- Built-in completers for:
- File paths
- Environment variables
- Choice lists
- Keyword arguments
- Multi-value inputs
- Extensible completion provider system
- Type-safe with comprehensive type hints
- Modern Python features (3.12+)
- Built-in help system
Installation
pip install slashed
Quick Example
from slashed import Command, CommandStore, CommandContext
from slashed.completers import ChoiceCompleter
# Create a command store
store = CommandStore()
# Define a command with completion support
async def greet(ctx: CommandContext, args: list[str], kwargs: dict[str, str]) -> None:
name = args[0] if args else "World"
greeting = kwargs.get("greeting", "Hello")
await ctx.output.print(f"{greeting}, {name}!")
greet_cmd = Command(
name="greet",
description="Greet someone",
execute_func=greet,
usage="[name] --greeting <greeting>",
help_text="Greet someone with a custom greeting.\n\nExample: /greet Phil --greeting Hi",
category="demo",
completer=ChoiceCompleter({
"World": "Default greeting target",
"Everyone": "Greet all users",
"Team": "Greet the team"
})
)
# Register the command
store.register_command(greet_cmd)
# Register built-in commands (help, etc)
store.register_builtin_commands()
# Create context and execute a command
ctx = store.create_context(data=None)
await store.execute_command("greet Phil --greeting Hi", ctx)
Generic Context Example
from dataclasses import dataclass
from slashed import Command, CommandStore, CommandContext
# Define your custom context data
@dataclass
class AppContext:
user_name: str
is_admin: bool
# Command that uses the typed context
async def admin_cmd(
ctx: CommandContext[AppContext],
args: list[str],
kwargs: dict[str, str],
) -> None:
if not ctx.data.is_admin:
await ctx.output.print("Sorry, admin access required!")
return
await ctx.output.print(f"Welcome admin {ctx.data.user_name}!")
# Create and register the command
admin_command = Command(
name="admin",
description="Admin-only command",
execute_func=admin_cmd,
category="admin",
)
# Setup the store with typed context
store = CommandStore()
store.register_command(admin_command)
# Create context with your custom data
ctx = store.create_context(
data=AppContext(user_name="Alice", is_admin=True)
)
# Execute command with typed context
await store.execute_command("admin", ctx)
Documentation
For full documentation including advanced usage and API reference, visit slashed.readthedocs.io.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Make sure to read our contributing guidelines first.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slashed-0.1.6.tar.gz.
File metadata
- Download URL: slashed-0.1.6.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
820eef743bc1bd9553db9c7a58a38dca5aa6daa5eaab2a026d1552ecefb202df
|
|
| MD5 |
df51ae5e95180bfeb8a75ef4c215c438
|
|
| BLAKE2b-256 |
e3c8c0e9d41ef715b91399d695a374f642054a14bac60884a27a105a3e5baef7
|
Provenance
The following attestation bundles were made for slashed-0.1.6.tar.gz:
Publisher:
build.yml on phil65/slashed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slashed-0.1.6.tar.gz -
Subject digest:
820eef743bc1bd9553db9c7a58a38dca5aa6daa5eaab2a026d1552ecefb202df - Sigstore transparency entry: 157078431
- Sigstore integration time:
-
Permalink:
phil65/slashed@8284d3255da91c44d12ffe0da1b461750d1c699e -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/phil65
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@8284d3255da91c44d12ffe0da1b461750d1c699e -
Trigger Event:
push
-
Statement type:
File details
Details for the file slashed-0.1.6-py3-none-any.whl.
File metadata
- Download URL: slashed-0.1.6-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6713ebd4fdd010858cc8c9c29588458e5a0d735275ebb637c7c9d5f83eb59234
|
|
| MD5 |
918ef8b2fcb1de7ac14b073ff680012b
|
|
| BLAKE2b-256 |
0f0a4413813401baeb762ad37a28492b9524774cb30a7fd7396714397a53e20a
|
Provenance
The following attestation bundles were made for slashed-0.1.6-py3-none-any.whl:
Publisher:
build.yml on phil65/slashed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slashed-0.1.6-py3-none-any.whl -
Subject digest:
6713ebd4fdd010858cc8c9c29588458e5a0d735275ebb637c7c9d5f83eb59234 - Sigstore transparency entry: 157078433
- Sigstore integration time:
-
Permalink:
phil65/slashed@8284d3255da91c44d12ffe0da1b461750d1c699e -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/phil65
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@8284d3255da91c44d12ffe0da1b461750d1c699e -
Trigger Event:
push
-
Statement type: