Bootwrap

Pure Python wrapper for one of the most popular front-end toolkit Bootstrap, allowing quick and easy prototyping of web-based user interfaces

Installation

Use the following command to install Python Bootwrap:

~$ pip install bootwrap

Single-Page Application

A single-page Bootwrap application looks something like this:

from flask import Flask
from markupsafe import Markup
from bootwrap import Page, Text

app = Flask(__name__)

@app.route('/')
def hello_world():
    return Markup(
        Page(container=[Text('Hello Word!')])
    )

if __name__ == '__main__':
    app.run(debug=True)

Multi-Pages Application

A multi-pages Bootwrap application looks something like this:

from flask import Flask
from markupsafe import Markup
from bootwrap import (
  Page, Menu, Image, Anchor, Button, Text
)

# Both 'logo.png' and 'favicon.ico' are
# stored in 'docs' folder
app = Flask(
  __name__,
  static_folder='docs',
  static_url_path=''
)

class MyMenu(Menu):
    def __init__(self):
        super().__init__(
            logo=Image(
              'logo.png',
              width=32,
              alt='Logo'),
            brand=Text('Bootwrap').\
              as_strong().\
              as_light().\
              ms(2),
            anchors=[
                Anchor('Home').\
                link('/'),
                Anchor('About').\
                link('/about')
            ], 
            actions=[
                Button('Sign In').\
                as_outline().\
                as_light().\
                link('/signin')
            ]
        )

class MyPage(Page):
    def __init__(self, container):
        super().__init__(
            favicon = 'favicon.ico',
            title='Hello World Application',
            menu=MyMenu(),
            container=container
        )

@app.route('/')
def home():
    return Markup(
      MyPage(container=[
        Text('Home').as_heading(1)
        ]
      )
    )

@app.route('/about')
def about():
    return Markup(
      MyPage(container=[
        Text('About').as_heading(1)
      ]
    )
  )

@app.route('/signin')
def signin():
    return Markup(
      MyPage(
        container=[
          Text('Sign In').as_heading(1)
        ]
      )
    )

if __name__ == '__main__':
    app.run(debug=True)