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.2.3.tar.gz (23.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: xFlask-0.2.3.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for xFlask-0.2.3.tar.gz
Algorithm Hash digest
SHA256 dc1ff420e60ba63ded7a5bf5c10846bf16eaf77ea88db82394cc99b63c48f37a
MD5 bbcabb4984b87d00bc0e31010fda20fe
BLAKE2b-256 be2ac915462a0951240ab508a8333fb5a10066566c5696f49ce3db7eb066f0ec

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