Skip to content

Commit

Permalink
formatted md for GFM support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cutwell committed Aug 9, 2023
1 parent dd392b7 commit 6581226
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/_pages/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ toc: true
---

# Caching expensive operations

`python-web-io` works by re-evaluating the target script after each user interaction, to progress the script to the next `input()`, etc.
This means expensive functions may be called more than once per session.
To reduce latency, a cache decorator is made available through the `python_web_io` module.
Expand Down
10 changes: 10 additions & 0 deletions docs/_pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ toc: true
---

# Configuration and settings

The appearance of generated pages are customisable via a `config.toml` file.
Create a subdirectory `/.pythonwebio` relative to were the project will be called from, and create a `config.toml` file inside.
```
Expand All @@ -15,6 +16,7 @@ Create a subdirectory `/.pythonwebio` relative to were the project will be calle
```

## Example `.envrc`

If using a `config.toml` file in a non-default location (and deploying via `uvicorn`), set the config filepath via the `PYTHON_WEB_IO_CONFIG` environment variable.

```bash
Expand All @@ -24,6 +26,7 @@ export PYTHON_WEB_IO_CONFIG=".pythonwebio/config.toml" # defaults to .pythonweb
```

## Example `config.toml`

```TOML
[script]
filepath = "app.py"
Expand Down Expand Up @@ -52,6 +55,7 @@ debug = false
```

## CLI

`python_web_io` is designed to be run (for production and development) using `uvicorn`. Use the [uvicorn settings](https://www.uvicorn.org/settings/) docs for a reference to setup your server.

For quick testing, `python_web_io` can also be ran as a Python script. Running directly spawns a `uvicorn` server with limited config options. Test mode is designed for evaluating multiple scripts quickly without editing a `config.toml` file, e.g.: testing the `/examples` scripts.
Expand All @@ -68,20 +72,24 @@ poetry run python_web_io --script="app.py" --config=".pythonwebio/config.toml" -
|`--port`|Set the Uvicorn server port (default: `8000`).|

## `config.toml` Documentation

### `[script]`

|||
|:---:|:---|
|`filepath`|Rather than provide a script filepath via command line, an app filepath can also be defined here.|
|`entrypoint`|Python scripts using the typical `if __name__ == '__main__': main()` will not run, as this check will fail. To resolve this, a function name can be supplied as an entrypoint for the script, and will be called to begin execution.|

### `[page]`

|||
|:---:|:---|
|`name`|Webapp name, used as the website / tab title.|
|`icon`|Webapp icon, used in bookmarks and in the tab.|
|`css`|Drop-in CSS styling is supported and encouraged to customise a web-app to user preference. A curated list of drop-in stylesheets can be found [here](https://github.com/sw-yx/spark-joy/blob/master/README.md#drop-in-css-frameworks). This option can be a list of stylesheets or a single item.|

### `[about]`

These options populate the `About` modal, accessible from the page footer.
|||
|:---:|:---|
Expand All @@ -90,6 +98,7 @@ These options populate the `About` modal, accessible from the page footer.
|`description`|A short description to summarise the webapp.|

### `[project]`

These options populate the `Help` modal, accessible from the page footer.
|||
|:---:|:---|
Expand All @@ -98,6 +107,7 @@ These options populate the `Help` modal, accessible from the page footer.
|`issues`|A link to a forum / issue tracker for reporting bugs users may encounter.|

### `[server]`

These options are for the underlying FastAPI server:
|||
|:---:|:---|
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ toc: true
---

# Installation

Install `python-web-io` locally using:
```bash
pip install python-web-io
Expand Down
4 changes: 4 additions & 0 deletions docs/_pages/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ toc: true
---

# I/O Overrides

`input()` and `print()` are overridden to add "magic" features.

## `print()`
Expand All @@ -14,6 +15,7 @@ toc: true
* Since strings are evaluated as raw HTML, this also allows use of `<img>`, `<style>` and `<script>` tags for more advanced app control (beware allowing unfiltered user input!).

### Examples

```python
# display some text wrapped in `small` HTML tags
print("<small>This is some subtext, it's not important.</small>")
Expand Down Expand Up @@ -51,6 +53,7 @@ print("<img id='logo' src='https://cdn2.iconfinder.com/data/icons/activity-5/50/
* By setting `attrs`, you can set additional attributes, such as `class` and `id`. Pass a dictionary in the format `{attribute: value}`, e.g.: `{'id': "myelement", 'class': "myclass"}`.

### Custom attribute examples

```python
# return a number between 1-100
input("Pick a number between 1-100", type='range', attrs={'min': 0, 'max': 100})
Expand All @@ -72,6 +75,7 @@ input("Enter your telephone number", type='tel', attrs={'pattern': "[0-9]{3}-[0-
```

## Custom option examples

For input types such as `button`, `radio` and `checkbox`, multiple inputs can be rendered at once. This is an optional argument for all inputs, but will only have an effect for these listed input types.

`button` and `radio` inputs can return a single option, or `None`, e.g.:
Expand Down
2 changes: 2 additions & 0 deletions docs/_pages/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ toc: true
---

# Quickstart

After installing the project, some environment setup is required:

## Required setup

Create an `app.py` file containing your script, a `config.toml` setting the script filepath and entrypoint, and an `.envrc` file to store project secrets. (Note: remember to add `.envrc` to your `.gitignore`). Look for example apps in [`/examples`](https://github.com/Cutwell/python-web-io/tree/main/python-web-io/examples).
```
.
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/static.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ toc: true
---

# Serving static files

If you wish to serve local files, such as custom `.css` stylesheets or images, they will need to be placed in the `./static` folder, relative to the project root.

```
Expand Down

0 comments on commit 6581226

Please sign in to comment.