Skip to main content

A Web Service Framework Base On Flask And Sqlalchemy

Project description

gt-webcore

Features

  • 自动序列化接口返回值为JSON结构;
  • 集成了SQLAlchemy、MongoEngine对象映射框架;
  • 统一的接口返回值结构;
  • 提供简单完善可扩展的接口参数验证机制;
  • 完善的异常处理机制;
  • 模块化方式加载应用模块,每个应用独立一个蓝图配置;

Install

With pip:

:: pip install gt-webcore

Configration

  1. MODULES - 加载模块列表

    { 'name': 'app.resource', 'package': 'resource' }
    
  2. LOGGER_CONFIG - 日志配置字典
    日志配置可以参考 python logging 的配置说明;

  3. SQLAlchemy 配置
    具体可以参考 Flask-SQLAlchemy 的配置说明,示例如下:

      SQLALCHEMY_ENGINE_OPTIONS = {  
        'pool_recycle': 3600,  
        'pool_timeout': 15,  
        'pool_pre_ping': True,  
        'pool_size': 5  
      }  
    
      SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:pwd@host:port/database?charset=utf8'
    
  4. MongoEngine 配置 配置项参考 Flask-MongoEngine 的配置说明,示例如下:

      MONGODB_SETTINGS = {
          'host': 'localhost',
          'port': 27017,
          'db': 'demo'
      }
    
  5. Celery 配置
    配置项参考 Celery 配置文档说明,示例如下:

      CELERY = {
        'celery_broker_url': 'redis://guest@localhost:6379',  
        'result_backend': 'redis://guest@localhost:6379',  
        'task_routes': { 'app.system.controller.*': {'queue': 'test'} }  
      }
    
  6. Cache 配置 配置项参考 Flask-Caching 的配置说明,示例如下:

      CACHE_TYPE = 'RedisCache'
      CACHE_DEFAULT_TIMEOUT = 300
      CACHE_REDIS_URL = 'redis://localhost:6379/2'
    

Run

from webcore import create_app, release_app

def debug_instance():
    from config.develop import DevelopConfig
    return create_app(DevelopConfig())

def production_instance():
    from config.production import ProductionConfig
    return create_app(ProductionConfig())

if __name__ == '__main__':
    app = debug_instance()
    app.run(host='0.0.0.0', port=5002, debug=True)
    release_app()

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

gt-webcore-0.2.9.tar.gz (11.9 kB view hashes)

Uploaded source

Built Distribution

gt_webcore-0.2.9-py3-none-any.whl (16.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page