Skip to main content

Lightweight Python Web Framework

Project description

BunnyPy

a Lightweight Python Web Framework

BunnyPy

PyPI Downloads License

English | 中文

Installation

pip install bunnypy

Simple Usage

a HelloWord Application

from bunnypy import Bunny

app = Bunny()

@app.controller
class IndexController:
    def ac_index(self):
        return 'Hello Bunny'

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

Data Model

from bunnypy import Bunny
import sqlite3

# ------------------------------------------------------------
# Config database using SQLite3

db = Bunny.SQLiteDatabase(sqlite3.connect('test.db'), 'tp_')
app = Bunny(database=db)

# ------------------------------------------------------------
# Declare a Model Class


@app.data
class Message:
    __pk__ = ['id']
    __ai__ = 'id'
    id = 'integer not null'
    msg = 'text not null'

    def __init__(self, msg=None):
        self.msg = msg


# ------------------------------------------------------------
# Create a table

Message.create() # create a table named "tp_message"

# ------------------------------------------------------------
# Insert Data

Message(msg="New Message").insert() # add a new row into table "tp_message"

# ------------------------------------------------------------
# Chained-call style query

# get one row where msg equals "Test"
Message.where(" msg = ? ",["Test"]).get(['id','msg'])

# get 10 rows of data starting at position 0 and sort by id in reverse order
size = 10
start = 0
Message.where().order(' id desc ').limit(size,start).get_all(['id','msg'])

Template

temp.html in template dir

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Template</title>
</head>
<body>
Output: {{ msg }}
</body>
</html>

Python code

from bunnypy import Bunny

app = Bunny()

@app.controller
class IndexController:
    def ac_index(self):
        return app.render('temp.html',{"msg":"Hello World"})


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

Project details


Download files

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

Files for BunnyPy, version 0.2.6
Filename, size File type Python version Upload date Hashes
Filename, size BunnyPy-0.2.6-py3-none-any.whl (9.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size BunnyPy-0.2.6.tar.gz (8.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page