Skip to main content

a python library for building web applications

Project description

Pyonir Web Framework

A static website generator and flat file web framework written in Python.

Install Pyonir

From pypi:

pip install pyonir

Create a new project

Manually create a main.py file from an empty directory with the following values.

Example

your_project/
    └─ main.py

Example main.py file

import pyonir
app = pyonir.init(__file__)

app.run()

or scaffold a demo web application from the cli:

> pyonir-create

This will generate the following directory structure

your_project/
    ├─ backend/
    ├─ contents/
    ├─ frontend/
    └─ main.py

Configure Contents

Site content is stored in special markdown files within the contents directory. Each sub directory within the contents folder represents the content type for any contained markdown files.

Content Types

Organizes a collection of files by specified types in a directory.

Configs: contents/configs

Represents mutable site configurations that can change while app is running.

Pages: contents/pages

Represents routes accessible from a URL. A file from contents/pages/about.md can be accessed from a URL of https:0.0.0.0/about All pages files are served as text/html resources. You can configure your pages to be serverd from a different directory by overriding the Site.PAGES_DIRNAME default value.

API: contents/api

Files within this folder represents API endpoints. Files here can define the response of the request and call python functions. A file from contents/api/new_post.md can be accessed from a URL of https:0.0.0.0/api/new_post. You can configure your api pages to be serverd from a different directory by overriding the Site.API_DIRNAME default value.

Generate static site

import pyonir
app = pyonir.init(__file__)

app.generate_static_website()

Run Web server

Pyonir uses the starlette webserver by default.

import pyonir
app = pyonir.init(__file__)

app.run(routes=[])

Configure Virtual Page Routes

Virtual routes

A virtual route can generate a page from aggregated data sources and giving more control on request response. Virtual routes can be defined within the contents/pages directory within a hidden .routes.md file. virtual routes can return the following response types:

  • HTML response
  • JSON response
  • WebSocket
  • Sever-Sent Events
  • Static file

JSON response

any pattern that begins with the default API url are automatically returning JSON.

/api/some_data/{data_id:str}: 
    GET.response: application/json
    data: hello {request.path_param.data_id} world

results from request http:0.0.0.0/api/some_data/a3b3c3

{
  "data": "hello a3b3c3 world"
}

HTML response

The page attribute value will be passed into the page request. The page url and slug are auto set from the request. Any scalar values will be passed as the page contents value. Only GET requests permitted by default.

/products/tags: 
    page:
        title: Products grouped by tags.
        contents: Listing of all products grouped by tags.
        template: product-tags.html
        entries: $dir/../products?groupby=tags

Server-sent events

/api/sse/user/notifications:
    GET.call: reference.path.to.sse.notifications.controller
    GET.headers.accept: text/event-stream

Websockets

/api/ws/user/chat:
    GET.call: path/to/websocket.py#module
    GET.headers.accept: text/event-stream

Configure Route Controllers

Configuration based routing defined at startup. All routes live in one place — easier for introspection or auto-generation. This allows flexibility for functions to be access from virtual routes and registered at startup.

def find_user(user_id: int):
    # perform logic using the typed arguments passed to this function on request
    pass

routes: list[PyonirRoute] = [
    ['/user/{user_id:int}', find_user, ["GET"]],
]

Configure Frontend

The frontend directory organizes your application themes. Each theme uses jinja template logic to generate data into HTML. Theme templates are stored in frontend/themes/{THEME_NAME}/layouts directory.

Configure Static Assets

...

Configure Plugins

...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyonir-0.0.20.tar.gz (110.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyonir-0.0.20-py3-none-any.whl (149.1 kB view details)

Uploaded Python 3

File details

Details for the file pyonir-0.0.20.tar.gz.

File metadata

  • Download URL: pyonir-0.0.20.tar.gz
  • Upload date:
  • Size: 110.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyonir-0.0.20.tar.gz
Algorithm Hash digest
SHA256 357a2640b93165d56cc3289d49b019350fe4dfa6027902314f6bc1c6fc4adf20
MD5 cb796e72afa99a08fc96fec8b17ef17f
BLAKE2b-256 6cc8325eba5f633705942d1125624e94d9943150102b90e313685e7e6f17a4fd

See more details on using hashes here.

File details

Details for the file pyonir-0.0.20-py3-none-any.whl.

File metadata

  • Download URL: pyonir-0.0.20-py3-none-any.whl
  • Upload date:
  • Size: 149.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyonir-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 2873a5dc537397e93223e1ce360f24b71e94762c8580e9f21afaf7a7b9ecc4a4
MD5 ece8a193a4b60312b5be574e91d20bcb
BLAKE2b-256 0b607908325dcb643d78582b327eda87819ddff673034e3b8147355d20fbc590

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page