Skip to main content

MVC framework for Python

Project description


© 2018 SiLeader and Cerussite.


PyMVC is MVC-like server side framework for python. This framework is using Flask.

How to

How to Install

pip install pymvc

How to Use

import pymvc

# setting: ex1
pymvc.settings.database.database = "pymmvc_example"

# router: ex1. Add route by method
class TopController(pymvc.Controller):
    VIEW = "top.html"

    def get(self, **kwargs):

pymvc.add_route("/", TopController)

# router: ex2. Add route by decorator
class UserController(pymvc.Controller):
    VIEW = "user.html"

    def get(self, id):
        return pymvc.render(id=id)

# model: ex1. User manager model
class User(pymvc.Model):
    name = pymvc.StringType()
    id = pymvc.UniqueIdType(primary=True)

if __name__ == '__main__': is Flask instance.

  1. set database name. (use pymvc.settings.database.database property)
  2. create classes
    • Controller class
    • Model class
  3. register controller classes to router.
  4. start app
    • call run() method.
    • use as WSGI app.


Controller class has VIEW (class variable) and get, post, put and delete instance methods. if you want to support GET method, override get method. these functions' default operation is return abort(404).


Model class is ORM for MongoDB (using pymongo). if inherit it, it creates collection.

collection's data is specified as class variable.

import pymvc

class Other1(pymvc.Model):

class ModelExample(pymvc.Model):
    string_data = pymvc.StringType()  # string
    int_data = pymvc.IntType()  # integer
    float_data = pymvc.FloatType()  # float
    unique_data = pymvc.UniqueIdType()  # UUID
    foreign_data1 = pymvc.ForeignType(Other1)  # other collection
    foreign_data2 = pymvc.ForeignType("Other2")  # other collection

class Other2(pymvc.Model):

collection name is snake case of class name. (e.g. User: user, UserInfo: user_info)

Model data type

model data types' constructor parameters are primary and default.

if primary is True, this value is marked as primary key. default is default value.


PyMVC add some Jinja2 function.

function operation
load_one(model, primary=None, **query) load one data (using find_one)
load_many(model, primary=None, **query) load all data match query and primary data

model is require parameter. primary is primary key value. key value hint is **query.


  • Flask
  • PyMongo
  • MongoDB


Apache License 2.0

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 pymvc, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size pymvc-0.1.3-py3-none-any.whl (21.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pymvc-0.1.3.tar.gz (13.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page