Skip to main content

Flask, Celery, SQLAlchemy integration toolkit

Project description

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

Why use Kit?

  • 3 great tools, 1 YAML configuration file. Versioning and keeping track of your different configuration options becomes almost fun.

  • With the kit command line tool, switching configurations is as simple as changing a flag: kit server -c dev.yaml vs. kit server -c prod.yaml.

  • Kit sets up the Flask, Celery and SQLAlchemy applications smartly, only creating those you need. It also makes sure database connections are correctly handled under the hood.

Kit is under development. You can find the latest version on GitHub.

Installation

$ pip install kit

Quickstart

Here is a minimalistic kit configuration file:

database_url: sqlite:///db.sqlite
flask:
  debug: yes
  testing: yes
engine:
  echo: yes

The flask and engine options are used to configure the Flask application and SQLAlchemy engine respectively (cf. Configuration for a full list of available options). The following code gives a sneak peak into how simple it then is to use these:

from kit import Kit

kit = Kit('/path/to/conf.yaml')

flask_app = kit.flask    # Flask app
celery_app = kit.celery  # Celery app
session = kit.session    # SQLAlchemy scoped session maker

# in this snippet we will only use flask_app

@flask_app.route('/')
def index():
  return 'Hello World!'

if __name__ == '__main__':
  flask_app.run()

For a more detailed example, take a look at the simple page view tracker in examples/view_tracker.

Configuration

The following options are special in a kit configuration file:

  • database_url: url to the database used.

  • flask: any valid flask configuration option.

  • celery: any valid celery configuration option.

  • engine: any valid engine configuration option.

  • session: any valid session maker configuration option.

  • commit_on_teardown: if True, the session will be committed after each request or task executed in a worker, otherwise the session is simply removed (default behavior).

  • modules: the list of modules that belong to this kit. This is used by the command line tool to know which modules to import.

  • root_folder: the kit’s root folder, the modules defines in modules should be importable from this folder (defaults to the configuration file’s directory).

  • flask_app_folder: the root folder of the Flask application, relative to root_folder (defaults to the same directory).

  • flask_static_folder: the Flask application’s static folder, relative to flask_app_folder (defaults to static/).

  • flask_template_folder: the Flask application’s template folder, relative flask_app_folder (defaults to templates/).

You can of course include other options in this file, these will be available on the conf kit attribute.

Command line tool

Kit includes a command line tool from where you can:

  • Launch the Flask built in Werkzeug server: kit server -p 5050 -d will start a server on port 5050 in debug mode.

  • Start Celery workers: kit worker will start a worker listening for tasks sent from your application.

  • Run the Flower monitoring tool: kit flower -p 8000

  • Run a shell in your project’s context: kit shell

Help is available for each command by typing kit <command> -h.

Extensions

Kit also comes with extensions for commonly needed functionalities:

  • Expanded SQLAlchemy models and queries

  • ReSTful API

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

kit-0.1.6.tar.gz (23.0 kB view details)

Uploaded Source

File details

Details for the file kit-0.1.6.tar.gz.

File metadata

  • Download URL: kit-0.1.6.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for kit-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1bb863f7f96c2a8ef38384370cd70d28c8641ad898157e4ce91e7a826138c24f
MD5 b68c2e54900cc3d4a83aa5a1c0f5fc21
BLAKE2b-256 e36e54a7a85ee9acc69b076936d22f74487f531e21b79e41f2c9b2bec429c7b1

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