Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install flasker

How to install flasker

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install flasker
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
0.1.45 Available View build log
Linux (64-bit)
0.1.45 Available View build log
 
License
MIT
Lastest release
version 0.1.45 on May 7th, 2013

Flasker is now deprecated.

Consider using Kit instead, which allows YAML configuration files, running multiple projects side by side and more.

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

  • What Flasker is!

    • A one stop .cfg configuration file for Flask, Celery and SQLAlchemy.
    • A simple pattern to organize your project via the flasker.current_project proxy (cf. Quickstart).
    • A command line tool from where you can launch the Flask buit in Werkzeug server, start Celery workers and the Flower tool, and run a shell in the current project context.
  • What Flasker isn't?

    • A simplified version of Flask, Celery, and SQLAlchemy. Some knowledge of these frameworks is therefore required.

Flasker is under development. You can find the latest version on GitHub and read the documentation on GitHub pages.

Installation

Using pip:

System Message: ERROR/3 (<string>, line 38)

Unknown directive type "code".

.. code:: bash

  $ pip install flasker

Using easy_install:

System Message: ERROR/3 (<string>, line 44)

Unknown directive type "code".

.. code:: bash

   $ easy_install flasker


Quickstart

This short guide will show you how to get an application combining Flask, Celery and SQLAlchemy running in moments (the code is available on GitHub in examples/basic/).

The basic folder hierarchy for a Flasker project looks something like this:

System Message: ERROR/3 (<string>, line 58)

Unknown directive type "code".

.. code:: bash

  project/
    conf.cfg    # configuration
    app.py      # code

Where conf.cfg is:

System Message: ERROR/3 (<string>, line 66)

Unknown directive type "code".

.. code:: cfg

  [PROJECT]
  MODULES = app

The MODULES option contains the list of python modules which belong to the project. Inside each of these modules we can use the flasker.current_project proxy to get access to the current project instance (which gives access to the configured Flask application, the Celery application and the SQLAlchemy database session registry). This is the only option required in a Flasker project configuration file.

Here is a sample app.py:

System Message: ERROR/3 (<string>, line 80)

Unknown directive type "code".

.. code:: python

   from flasker import current_project

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

   # for this simple example we will only use flask_app

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

Once these two files are in place, we can already start the server! We simply run (from the command line in the project/ directory):

System Message: ERROR/3 (<string>, line 97)

Unknown directive type "code".

.. code:: bash

   $ flasker server
   * Running on http://0.0.0.0:5000/

We can check that our server is running for example using Requests (if we navigate to the same URL in the browser, we would get similarly exciting results):

System Message: ERROR/3 (<string>, line 106)

Unknown directive type "code".

.. code:: python

   In [1]: import requests
   In [2]: print requests.get('http://localhost:5000/').text
   Hello World!


Configuring your project

In the previous example, the project was using the default configuration, this can easily be changed by adding options to the conf.cfg file. Here is an example of a customized configuration file:

System Message: ERROR/3 (<string>, line 120)

Unknown directive type "code".

.. code:: cfg

  [PROJECT]
  MODULES = app
  [ENGINE]
  URL = sqlite:///db.sqlite   # the engine to bind the session on
  [FLASK]
  DEBUG = true                # generic Flask options
  TESTING = true

For an exhaustive list of all the options available, please refer to the documentation on GitHub Pages.

Finally, of course, all your code doesn't have to be in a single file. You can specify a list of modules to import in the MODULES option, which will all be imported on project startup. For an example of a more complex application, you can check out the code in examples/flisker.

Next steps

Under the hood, on project startup, Flasker configures Flask, Celery and the database engine and imports all the modules declared in MODULES (the configuration file's directory is appended to the python path, so any module in our project/ directory will be accessible).

There are two ways to start the project.

  • The simplest is to use the flasker console tool:

    System Message: ERROR/3 (<string>, line 151)

    Unknown directive type "code".

    .. code:: bash
    
      $ flasker -h
    
    

    This will list all commands now available for that project:

    • server to run the Werkzeug app server
    • worker to start a worker for the Celery backend
    • flower to run the Flower worker management app
    • shell to start a shell in the current project context (using IPython if it is available)

    Extra help is available for each command by typing:

    System Message: ERROR/3 (<string>, line 165)

    Unknown directive type "code".

    .. code:: bash
    
      $ flasker <command> -h
    
    
  • Or you can load the project manually:

    This is useful for example if you are using a separate WSGI server or working from an IPython Notebook.

    System Message: ERROR/3 (<string>, line 174)

    Unknown directive type "code".

    .. code:: python
    
       from flasker import Project
    
       project = Project('path/to/default.cfg')
    
    

To read more on how to user Flasker and configure your Flasker project, refer to the documentation on GitHub pages.

Extensions

Flasker also comes with extensions for commonly needed functionalities:

  • Expanded SQLAlchemy base and queries
  • ReSTful API
  • Authentication via OpenID (still alpha)

Subscribe to package updates

Last updated May 7th, 2013

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.