Create awesome command line applications with less effort
Project description
Eggella
Eggella is a shield volcano in central Kamchatka. The volcano is located on the west axis of the southern Sredinny Range.
About
Eggella is a framework for easy creating interactive prompt-line applications.
Design inspired by vulcano and various chatbots frameworks and built top on prompt-toolkit
Features:
- python 3.8+ support
- arguments auto cast from function annotations
- cross-platform (prompt-toolkit guarantees)
- FSM
- customized events
- completer
- ctx storage (dict)
Install
pip install eggella
Examples:
Basic
from eggella import Eggella
app = Eggella(__name__)
@app.on_startup()
def startup_event():
print("Hello! this quick Eggella app example!")
@app.on_close()
def close_event():
print("Goodbye! :D")
@app.on_command()
def hello():
return "Hello, world!"
@app.on_command("sum")
def sum_(*args: int):
return sum(args)
if __name__ == '__main__':
app.loop()
FSM example
from typing import Optional
from prompt_toolkit.validation import Validator
from eggella import Eggella
from eggella.fsm import IntStateGroup
class LoginForm(IntStateGroup):
EMAIL = 0
PASSWORD = 1
ACCEPT = 2
# prompt validators
password_validator = Validator.from_callable(
lambda s: len(s) > 6,
error_message="password len should be bigger than 6")
email_validator = Validator.from_callable(
lambda s: "@" in s,
error_message="email is not valid")
app = Eggella(__name__)
app.register_states(LoginForm)
@app.on_command("auth")
def auth(email: Optional[str] = None, password: Optional[str] = None):
"""auth to service.
if email and password not passed - invoke interactive auth
"""
if email and password:
print("Success auth!")
print("Email:", email)
print("Password:", "*" * len(password))
else:
app.fsm.run(LoginForm)
@app.on_state(LoginForm.EMAIL)
def email():
app.fsm.ctx["email"] = app.cmd.prompt("Enter email > ", validator=email_validator)
app.fsm.next()
@app.on_state(LoginForm.PASSWORD)
def password():
# alias from prompt_toolkit.prompt functon
app.fsm.ctx["password"] = app.cmd.prompt("Enter password > ", is_password=True, validator=password_validator)
app.fsm.next()
@app.on_state(LoginForm.ACCEPT)
def finish():
auth(app.fsm["email"], app.fsm["password"])
# need close FSM
app.fsm.finish()
if __name__ == '__main__':
app.loop()
Documentation
TODO
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
eggella-0.0.3.tar.gz
(12.1 kB
view details)
Built Distribution
eggella-0.0.3-py3-none-any.whl
(16.1 kB
view details)
File details
Details for the file eggella-0.0.3.tar.gz
.
File metadata
- Download URL: eggella-0.0.3.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9de6ff8f8e368f8ae5005196b3d8760419524a42f5e2b3402fc4a2b6cb2f2e6c |
|
MD5 | a2549627c9ab790a25b097bda8a37642 |
|
BLAKE2b-256 | bb1b44f6849e464ad14b61b79401b70b45413044469858cb1e1247146390a1b5 |
File details
Details for the file eggella-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: eggella-0.0.3-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1349f72caf148e3cfc109fb9ced1127e424190e8344eee029adb9b53bbf9f2c9 |
|
MD5 | f0a1a1576f798deb3acbf04636181ab3 |
|
BLAKE2b-256 | f43db11af690c91206087c66fdc5d3d818fc3a5dd658dd8ea374059479109f39 |