/python-vial

A session store backed by redis.

Primary LanguagePythonMIT LicenseMIT

vial

Build Status Coverage Status PyPi Version PyPi Downloads

A session store backed by redis.

Installation

Automated

  1. Vial can be installed using pip or easy_install.

    pip install vial

Manual

  1. Clone the vial repository to your local computer.

    git clone git://github.com/vial/python-vial.git
  2. Change into the vial root directory.

    cd /path/to/python-vial
  3. Install the project and all its dependencies using pip.

    pip install .

    Additional extra requirements may be specified in brackets following the ..

    # Install vial as well as the additional dependencies to use
    # the unit test suite.
    pip install ".[test]"

Usage

The session object is a standard mutable mapping with a few additional methods to facilitate a session.

Establish a new session

>>> from vial import Vial

# By default the session connects to redis on `localhost:6379`.
>>> vial = Vial(host='localhost', port=9001)

>>> session = vial.Session()
>>> session.id
None

>>> session.save()
>>> session.id
'8379fh98302hf8hg8hrligh908h490nvn9gn389tb038n'

# Add some more values to the session.
>>> session['color'] = 'blue'
>>> session.save()

# Fetch the session and check the value.
>>> vial.Session(id=session.id)['color']
'blue'

Retrieve an existing session

This will create the session object bound to the passed identifier.

>>> from vial import Vial
>>> vial = Vial()
>>> session = vial.Session(id='8379fh98302hf8hg8hrligh908h490nvn9gn389tb038n')

# This will identify if the session is persisted in redis
>>> session.is_new
False

Contributing

Setting up your environment

  1. Follow steps 1 and 2 of the manual installation instructions.
  1. Initialize a virtual environment to develop in. This is done so as to ensure every contributor is working with close-to-identicial versions of packages.

    mkvirtualenv vial

    The mkvirtualenv command is available from virtualenvwrapper which can be installed as follows:

    pip install virtualenvwrapper
  2. Install vial in development mode with testing enabled. This will download all dependencies required for running the unit tests.

    pip install -e ".[test]"

Running the test suite

  1. Set up your environment.

  2. Run the unit tests.

    py.test

License

Unless otherwise noted, all files contained within this project are liensed under the MIT opensource license. See the included file LICENSE or visit opensource.org for more information.