Coder Social home page Coder Social logo

kit's Introduction

Kit

A configurable, lightweight framework that integrates Flask, SQLAlchemy, and Celery.

  • Configure all your applications and sessions from one file (cf. Quickstart for an example).
  • Run your project from the command line: Start the Werkzeug webserver, start Celery workers, start a shell in your project's context (using IPython if available), and start the Flower monitor using the kit command line tool.
  • No more complicated import schemes: kit.Flask and kit.Celery always return the correct (and configured) application corresponding to the module.
  • Kit makes sure database connections are correctly handled (e.g. removed after each request and task) under the hood. You can configure this behavior via the kit.teardown_handler decorator.

Check out the examples/ folder for a few sample applications or read the full documentation on GitHub pages.

Kit is under development.

Installation

$ pip install kit

Quickstart

Sample configuration file:

root: '..'
flasks:
  - modules: ['my_project.app', 'my_project.app.views']
    kwargs:
      static_folder: 'st'
    config:
      debug: yes
      testing: yes
  - modules: ['my_project.api']
celeries:
  - modules: ['my_project.tasks']
    config:
      broker_url: 'redis://'
sessions:
  db:
    url: 'mysql://...'
    engine:
      pool_recycle: 3600
    options:
      commit: yes
      raise: no
modules: ['my_project.startup']

The following configuration options are available:

  • root: project root, will be added to your python path (defaults to '.')
  • flasks: list of Flask application settings. Each item has the following keys available:
    • modules: list of modules where this application is used. Inside each of these modules, you can use kit.Flask(__name__) to recover this configured application. The application's name will be automatically generated from this list of modules.
    • kwargs: dictionary of keyword arguments passed to the flask.Flask constructor.
    • config: dictionary of configuration options used to configure the application. Names are case insensitive so no need to uppercase them.
  • celeries: list of Celery application settings. Each item has the following keys available:
    • modules: list of modules where this application is used. Inside each of these modules, you can use kit.Celery(__name__) to recover this configured application. The application's name will be automatically generated from this list of modules.
    • kwargs: dictionary of keyword arguments passed to the celery.Celery constructor.
    • config: dictionary of configuration options used to configure the application. Names are case insensitive so no need to uppercase them.
  • sessions: dictionary of sessions. The key is the session name (used as argument to kit.get_session). Each item has the following settings available:
    • url: the database url (defaults to sqlite://)
    • kwargs: dictionary of keyword arguments to pass to sqlalchemy.orm.sessionmaker.
    • engine: dictionary of keyword arguments to pass to the bound engine's constructor.
    • options: there are currently two options available:
      • commit: whether or not to commit the session after each request or task (defaults to False).
      • raise: whether or not to reraise any errors found during commit (defaults to True).
  • modules: list of modules to import (and that don't belong to an application).

You can then manage your project using the kit command line tool:

  • kit shell will start a shell in your project's environment (all applications and sessions will have been created and set up beforehand).
  • kit server will run the Werkzeug server for one of your Flask applications (if several applications are found, you will be prompted to choose one).
  • kit worker will start a Celery worker (if more than one Celery application exists in your project, you will be prompted to choose one).
  • kit flower starts the Flower worker monitor.

kit -h displays usage and the list of options available for each of these commands.

Next steps

To instantiate an application outside of the command line tool (for example to run it on a different WSGI server), you can specify a path argument to the kit.Flask function. This will load the kit before returning the application. The path argument is available on all other functions as well (for example to allow model access from an IPython notebook).

Next features

  • kit.setup(path, name=None) to load the kit. name=__name__ can be passed as keyword argument to disable effect if not run as main module (for testing). This method would replace kit.get_kit. Suggested example usage:

    import kit
    
    kit.setup('conf/path.yaml', name=__name__)
    app = kit.Flask(__name__)
    
    from project.models import orm
    
    # ...

kit's People

Contributors

colwilson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kit's Issues

flasker server instruction fails - twice

workon flasker-trial
cdvirtualenv
pip install --upgrade flasker

Requirement already up-to-date: flasker in ./lib/python2.7/site-packages
Requirement already up-to-date: celery in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: flask in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: flask-login in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: sqlalchemy in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: redis in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: flower in ./lib/python2.7/site-packages (from flasker)
Requirement already up-to-date: billiard>=2.7.3.21,<3.0 in ./lib/python2.7/site-packages (from celery->flasker)
Requirement already up-to-date: python-dateutil>=1.5,<2.0 in ./lib/python2.7/site-packages (from celery->flasker)
Requirement already up-to-date: kombu>=2.5.6,<3.0 in ./lib/python2.7/site-packages (from celery->flasker)
Requirement already up-to-date: Werkzeug>=0.7 in ./lib/python2.7/site-packages (from flask->flasker)
Requirement already up-to-date: Jinja2>=2.4 in ./lib/python2.7/site-packages (from flask->flasker)
Requirement already up-to-date: tornado in ./lib/python2.7/site-packages (from flower->flasker)
Requirement already up-to-date: anyjson>=0.3.3 in ./lib/python2.7/site-packages (from kombu>=2.5.6,<3.0->celery->flasker)
Requirement already up-to-date: amqp>=1.0.8,<1.1.0 in ./lib/python2.7/site-packages (from kombu>=2.5.6,<3.0->celery->flasker)
Cleaning up...

rm -fr app default.cfg
flasker new basic
flasker server

Traceback (most recent call last):
File "/home/col/Projects/flasker-trial/bin/flasker", line 9, in
load_entry_point('flasker==0.1.28', 'console_scripts', 'flasker')()
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/main.py", line 268, in main
parsed_args.handler(parsed_args)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/main.py", line 57, in wrapper
pj._make(app, celery)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/project.py", line 116, in _make
self._engine = create_engine(engine_ops.pop('url'), **engine_ops)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/sqlalchemy/engine/init.py", line 331, in create_engine
return strategy.create(_args, *_kwargs)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 72, in create
(cargs, cparams) = dialect.create_connect_args(u)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 315, in create_connect_args
" sqlite:////absolute/path/to/file.db" % (url,))
sqlalchemy.exc.ArgumentError: Invalid SQLite URL: sqlite://db.sqlite
Valid SQLite URL forms are:
sqlite:///:memory: (or, sqlite://)
sqlite:///relative/path/to/file.db
sqlite:////absolute/path/to/file.db

after fixing the sqlite url to URL = sqlite:///db.sqlite

flasker server

Traceback (most recent call last):
File "/home/col/Projects/flasker-trial/bin/flasker", line 9, in
load_entry_point('flasker==0.1.28', 'console_scripts', 'flasker')()
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/main.py", line 268, in main
parsed_args.handler(parsed_args)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/main.py", line 57, in wrapper
pj._make(app, celery)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/flasker/project.py", line 116, in _make
self._engine = create_engine(engine_ops.pop('url'), **engine_ops)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/sqlalchemy/engine/init.py", line 331, in create_engine
return strategy.create(_args, *_kwargs)
File "/home/col/Projects/flasker-trial/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 141, in create
engineclass.name))
TypeError: Invalid argument(s) 'pool_size' sent to create_engine(), using configuration SQLiteDialect_pysqlite/NullPool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

Can't config CELERY_QUEUES in cfg file

Matthieu, I'm having trouble finding a nice way to configure CELERY_QUEUES in the cfg file, it's a dict normally.

Any bright ideas how this could be dealt with?

Typo in ext/orm.py

Hi,

There is a typo in orm.py, line 251:

@declared_attr
def tablename(cls):
"""Automatically create the table name."""
return '%ss' % uncamelcase(cls.name)

Note the %ss

I noticed this when using Flask-Restless with this ORM to create tables.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.