Skip to main content

Python Web Framework

Project description

xFlask combines the extensions of Flask and it is designed to make getting started quick and easy to build Restful web service, with the ability to scale up to complex applications. It begin as a simple wrapper around Flask and its extensions to provide a simple platform to ease API development.

1. Functionalities

  • Follow concepts of Model, Data Access Object (DAO), Service and Controller
  • Ease to decouple component dependencies by using Flask-Injector
  • Provide a simple way to validate Value Object (VO) by using Marshmallow
  • Adapt with Flask-Migration to easily maintain the database schema
  • Provide simple logging API helping to debug the application flow
  • Adapt with Flask-Testing for testing the application components

2. Usages

  • Model
from xflask.sqlalchemy import Column, Integer, String
from xflask.sqlalchemy.model import AuditModel

class User(AuditModel):

    id          = Column(Integer, primary_key=True)
    username    = Column(String(50), unique=True, nullable=False)
    password    = Column(String(50), unique=False, nullable=False)
  • DAO
from xflask.dao import Dao

from main.model.user import User

class UserDao(Dao):

    def __init__(self):
        super(UserDao, self).__init__(User)

    def get_by_username(self, username):
        return self.query().filter_by(username=username).first()
  • Service
from injector import inject

from xflask.service import CrudService

from main.dao.user import UserDao

class UserService(CrudService):

    @inject
    def __init__(self, dao: UserDao):
        super(UserService, self).__init__(dao)

    def get_user(self, user_id):
        return self.user_dao.get_user(user_id)
  • Controller
from injector import inject

from xflask.classy import route, JsonBody
from xflask.controller import Controller
from xflask.web.response import Response

from main.controller.vo.user import UserVo
from main.model.user import User
from main.service.user import UserService

class UserController(Controller):

    route_base = '/api/user/'

    @inject
    def __init__(self, user_service: UserService):
        self.user_service = user_service
    
    @route('<user_id>')
    def get(self, user_id):
        user = self.user_service.get(user_id)
        if user is None:
            return Response.not_found()

        return Response.success(user)
        
    @route('', methods=['PUT'])
    def update(self, user: JsonBody(UserVo)):
        self.user_service.update(User(**user))

        return Response.success()
  • Value Object (VO)
from xflask.marshmallow import Int, Str
from xflask.marshmallow import validate

from xflask.web.vo import Vo

class UserVo(Vo):

    id          : Int(required=True)
    username    : Str(validate=validate.Length(min=2, max=50), required=True)
    password    : Str(validate=validate.Length(min=2, max=50), required=True)

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

xFlask-0.1.2.tar.gz (18.1 kB view details)

Uploaded Source

File details

Details for the file xFlask-0.1.2.tar.gz.

File metadata

  • Download URL: xFlask-0.1.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for xFlask-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f1c88c39c899b6178633c3374bce82a52a669afc716ce620fb4b7ffb7b4d7bad
MD5 4f8c5c7dff5a8d280a5cc45713928ece
BLAKE2b-256 421ea4e4dd9a5905b1b79cf6e5c30930c160c57cf879f30dabfa11602eed52a1

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