Skip to main content

PyMVC

© 2018 SiLeader and Cerussite.

Overview

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):
        pass


pymvc.add_route("/", TopController)


# router: ex2. Add route by decorator
@pymvc.route("/users/<id>")
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__':
    pymvc.app.run()

pymvc.app 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 pymvc.app as WSGI app.

Controller

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

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):
    pass


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):
    pass

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.

View

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.

Dependencies

  • Flask
  • PyMongo
  • MongoDB

License

Apache License 2.0

Metadata

Release files for pymvc 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymvc 0.1.3
File Size Uploaded
pymvc-0.1.3.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymvc 0.1.3
File Interpreter ABI Platform
pymvc-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 35.0 kB

Release files / pymvc-0.1.3.tar.gz

Download URL pymvc-0.1.3.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dd9a8f91c227a8ebe19347b54e7e34ff2855959bb23607d4eb62b4df07daec47
BLAKE2b-256 checksum
How to use checksums
dc096e8b5a6d8eaf2c971e8e01b61fcb747ca1cf9d486d4a2cfcc7917fdc16d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pymvc-0.1.3-py3-none-any.whl

Download URL pymvc-0.1.3-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
379b773fb4181172295a85dfddde78d919758ed90737196e6c30c152bb9b361f
BLAKE2b-256 checksum
How to use checksums
6fb9b49db8335bb4a9b32112fc839bd787a80fa2112b34679a0d767d892c2ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page