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.

Source Distribution

BunnyPy-0.2.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

BunnyPy-0.2.4-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file BunnyPy-0.2.4.tar.gz.

File metadata

  • Download URL: BunnyPy-0.2.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for BunnyPy-0.2.4.tar.gz
Algorithm Hash digest
SHA256 02eda5770f2478327480a546b26402e9bc6f264b15e172f7070e28ad2947c0c1
MD5 e18816c59a3bd91f337c3e466c55d1e2
BLAKE2b-256 eefece22bb002c9f187448a88ed4b1f541f7469b08d510ebcd89e4a3e78cc369

See more details on using hashes here.

File details

Details for the file BunnyPy-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: BunnyPy-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for BunnyPy-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a406647d7dd8f1ace1fde6ddb4bf33ad6649322e9f89170e2b94e782ee112579
MD5 9ce574f813431a6b48f85e6474d96b5b
BLAKE2b-256 5f74569242d33e489a8f76f9111133a0d18d6c460bb3c283d155958de8592378

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