sufficient
A framework for creating Frame apps in an intuitive and declarative manner.
Installation
pip install sufficient
Quick Start
The code below is from frame-app-boilerplate.
- Create a Python project with the following directory structure.
api
└── index.py
frame
├── app.py
├── static
│ └── home.svg
└── templates
└── foo.svg
- Define your frame app in frame/app.py.
from sufficient.frames import *
class App:
name = "GM Universe"
description = "A boilerplate for creating frame apps"
image = "{uri}/static/home.svg"
uri = "{uri}"
start = "PageHome"
class PageHome:
def view(self, action: Action, result: ActionResult):
return SvgFile("home.svg")
def btn_normal_button(self, action: Action):
return "PageNext"
def goto_redirect_button(self, action: Action):
return "https://github.com/briceyan/frame-app-boilerplate"
def input_input_text(self, action: Action):
# wip
pass
class PageNext:
def view(self, action: Action, result: ActionResult):
return SvgTemplate("foo.svg", title="PageNext", content="hello")
def btn_prev(self, action: Action):
return "PageHome"
def btn_refresh(self, action: Action):
return "PageNext"
- In api/index.py, create routes as endpoints of your frame server.
from flask import Flask, request, send_from_directory, redirect
import os
import io
import json
from sufficient.frames import FrameAppRunner
from frame import app as frame_app
app = Flask(__name__, instance_relative_config=True)
static_dir = os.path.abspath("frame/static")
templates_dir = os.path.abspath("frame/templates")
# data_dir = app.instance_path
data_dir = "/tmp/data"
runner = FrameAppRunner(frame_app, static_dir,
templates_dir, data_dir=data_dir)
try:
os.makedirs(data_dir)
except OSError:
pass
@app.route('/')
def frame_index():
framelet = runner.start()
return runner.gen_frame_html(framelet, request.host_url, og=True)
@app.route('/static/<string:path>')
def frame_static(path):
return send_from_directory(static_dir, path)
@app.route('/view/<string:path>')
def frame_image(path):
return send_from_directory(data_dir, path)
@app.route('/<string:page>/click', methods=['POST'])
def frame_click(page):
tag, value = runner.click(page, request.json)
if tag == "framelet":
return runner.gen_frame_html(value, request.host_url)
elif tag == "redirection":
return redirect(value, code=302)
- Run your app locally for testing
python3 -m venv venv
source venv/bin/activate
pip install sufficient flask
python -m flask --app api.index run
- Use ngrok to make your local server publically accessible
ngrok http 5000 --scheme http,https
- Validate your frame app
- Deploy
The following instructions are assuming you are going to deploy on vercel. see https://vercel.com/docs/functions/serverless-functions/runtimes/python for more info.
create vercel.json with content:
{
"rewrites": [{ "source": "/(.*)", "destination": "/api/index" }]
}
vercel deploy
License
sufficient is distributed under the terms of the MIT license.
Metadata
Release files for sufficient 0.1.3
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 | Actions |
|---|---|---|---|---|
| sufficient-0.1.3.tar.gz | 12.1 kB | Without provenance | Details for sufficient-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sufficient-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for sufficient-0.1.3-py3-none-any.whl |
Total release size: 22.2 kB
Release files / sufficient-0.1.3.tar.gz
| Download URL | sufficient-0.1.3.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30f70ceb8168266667d5504ea03408dfaa4ff31189e959da668ee38aacfd7f44
|
|
BLAKE2b-256 checksum How to use checksums |
317b0b0b20f12958aeed76d8ed7224f6548cb449580414195644cd6da3c7075f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.26.0
|
Release files / sufficient-0.1.3-py3-none-any.whl
| Download URL | sufficient-0.1.3-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bfd66df4962fc0020f0b9795b92c0397999fe164bd2b073fb3ff8c64285ff68
|
|
BLAKE2b-256 checksum How to use checksums |
a230e5234ca3ed93d9f444df06afca438ebf8fa18068c473a25464d577404579
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.26.0
|
Security for sufficient 0.1.3
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.