a framework for interactive, page-based console applications
Synopsis
The almanac framework aims to serve as an intuitive interface for spinning up interactive, page-based console applications. Think of it as a Python metaprogramming layer on top of Python Prompt Toolkit and Pygments.
Example
almanac turns this:
"""Welcome to a simple interactive HTTP client.
The current URL to request is the application's current path. Directories will be
created as you cd into them.
"""
import aiohttp
import asyncio
from almanac import highlight_for_mimetype, make_standard_app, PagePath
app = make_standard_app()
@app.on_init()
async def runs_at_start_up():
app.io.raw(__doc__)
app.bag.session = aiohttp.ClientSession()
app.io.info('Session opened!')
@app.on_exit()
async def runs_at_shut_down():
await app.bag.session.close()
app.io.info('Session closed!')
@app.prompt_text()
def custom_prompt():
stripped_path = str(app.page_navigator.current_page.path).lstrip('/')
return f'{stripped_path}> '
@app.hook.before('cd')
async def cd_hook_before(path: PagePath):
if path not in app.page_navigator:
app.page_navigator.add_directory_page(path)
@app.hook.exception(aiohttp.ClientError)
async def handle_aiohttp_errors(exc: aiohttp.ClientError):
app.io.error(f'{exc.__class__.__name__}: {str(exc)}')
@app.cmd.register()
@app.arg.method(choices=['GET', 'POST', 'PUT'], description='HTTP verb for request.')
@app.arg.proto(choices=['http', 'https'], description='Protocol for request.')
async def request(method: str, *, proto: str = 'https', **params: str):
"""Send an HTTP or HTTPS request."""
path = str(app.current_path).lstrip('/')
url = f'{proto}://{path}'
app.io.info(f'Sending {method} request to {url}...')
resp = await app.bag.session.request(method, url, params=params)
async with resp:
text = await resp.text()
highlighted_text = highlight_for_mimetype(text, resp.content_type)
app.io.info(f'Status {resp.status} response from {resp.url}')
app.io.info('Here\'s the content:')
app.io.ansi(highlighted_text)
if __name__ == '__main__':
asyncio.run(app.prompt())
Into this:
Installation
You can download the latest packaged version from PyPI:
pip install almanac
Alternatively, you can get the bleeding-edge version from version control:
pip install https://github.com/welchbj/almanac/archive/master.tar.gz
License
The original content of this repository is licensed under the MIT License, as per the LICENSE.txt file.
Some of the parsing logic is borrowed from the python-nubia project and is licensed under that project's BSD License. For more information, please see the comment in almanac/parsing/parsing.py.
Development
Development dependencies can be installed with:
pip install -r deps/dev-requirements.txt
To run the tests, use:
python tasks.py test
To lint and type check the code, use:
flake8 .
mypy .
When it's time to cut a release, use:
python setup.py bdist_wheel sdist
twine check dist/*.whl dist/*.gz
twine upload dist/*.whl dist/*.gz
Metadata
Release files for almanac 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| almanac-0.1.0.tar.gz | 45.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| almanac-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 117.5 kB
Release files / almanac-0.1.0.tar.gz
| Download URL | almanac-0.1.0.tar.gz |
|---|---|
| Size | 45.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
585c2c96c19de1ba81c62d39d96c152de2bed5732da7f412fe834272a118af27
|
|
BLAKE2b-256 checksum How to use checksums |
50ae34a58f485ac9cc97f8f3342ed7e4016a1b043ecf77f20b20697b65c8a259
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.0
|
Release files / almanac-0.1.0-py3-none-any.whl
| Download URL | almanac-0.1.0-py3-none-any.whl |
|---|---|
| Size | 71.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7aecd677fa11266ec84944cda7bf6a1f89054d68f102e8dab2c199dc5df65158
|
|
BLAKE2b-256 checksum How to use checksums |
18c06fbdf16df6a321b5dd309a4e87ba29937acab2c513b8b2998b578521547e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.0
|
Security for almanac 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.