Skip to main content

A web framework built on Flask & SQLAlchemy. Somewhere North of Flask but South of Django.

Project description

https://codecov.io/github/level12/keg/coverage.svg?branch=master https://img.shields.io/pypi/v/Keg.svg https://img.shields.io/pypi/l/keg.svg https://img.shields.io/pypi/pyversions/keg.svg https://img.shields.io/pypi/status/Keg.svg AppVeyor Build

Keg is an opinionated but flexible web framework built on Flask and SQLAlchemy.

Keg’s Goal

The goal for this project is to encapsulate Flask best practices and libraries so devs can avoid boilerplate and work on the important stuff.

We will lean towards being opinionated on the big things (like SQLAlchemy as our ORM) while supporting hooks and customizations as much as possible.

Think North of Flask but South of Django.

Features

Default Logging Configuration

We highly recommend good logging practices and, as such, a Keg application does basic setup of the Python logging system:

  • Sets the log level on the root logger to INFO

  • Creates two handlers and assigns them to the root logger:

    • outputs to stderr

    • outputs to syslog

  • Provides an optional json formatter

The thinking behind that is:

  • In development, a developer will see log messages on stdout and doesn’t have to monitor a file.

  • Log messages will be in syslog by default and available for review there if no other action is taken by the developer or sysadmin. This avoids the need to manage log placement, permissions, rotation, etc.

  • It’s easy to configure syslog daemons to forward log messages to different files or remote log servers and it’s better to handle that type of need at the syslog level than in the app.

  • Structured log files (json) provide metadata details in a easy-to-parse format and should be easy to generate.

  • The options and output should be easily configurable from the app to account for different needs in development and deployed scenarios.

  • Keg’s logging setup should be easy to turn off and/or completely override for situations where it hurts more than it helps.

Installation

pip install keg

App Configuration

CLI Command

The command <myapp> develop config will give detailed information about the files and objects being used to configure an application.

Profile Priority

All configuration classes with the name DefaultProfile will be applied to the app’s config first.

Then, the configuration classes that match the “selected” profile will be applied on top of the app’s existing configuration. This makes the settings from the “selected” profile override any settings from the DefaultProfile.

Practically speaking, any configuration that applies to the entire app regardless of what context it is being used in will generally go in myapp.config in the DefaultProfile class.

Selecting a Configuration Profile

The “selected” profile is the name of the objects that the Keg configuration handling code will look for. It should be a string.

A Keg app considers the “selected” profile as follows:

  • If config_profile was passed into myapp.init() as an argument, use it as the selected profile. The --profile cli option uses this method to set the selected profile and therefore has the highest priority.

  • Look in the app’s environment namespace for “CONFIG_PROFILE”. If found, use it.

  • If running tests, use “TestProfile”. Whether or not the app is operating in this mode is controlled by the use of:

    • myapp.init(use_test_profile=True) which is used by MyApp.testing_prep()

    • looking in the app’s environment namespace for “USE_TEST_PROFILE” which is used by keg.testing.invoke_command()

  • Look in the app’s main config file (app.config) and all it’s other config files for the variable DEFAULT_PROFILE. If found, use the value from the file with highest priority.

Keg Development

To develop on keg, begin by installing dependencies and running the tests:

git clone https://github.com/level12/keg keg-src
cd keg-src

cp keg_apps/db/user-config-tpl.py ~/.config/keg_apps.db/keg_apps.db-config.py
# edit the DB connection info in this file (you don't have to use vim):
vim ~/.config/keg_apps.db/keg_apps.db-config.py

pipenv --python=python3.6
pipenv install
pipenv run pytest keg

You can then examine tox.ini for insights into our development process. In particular, we:

  • use py.test for testing (and coverage analysis)

  • use flake8 for linting

Preview Readme

When updating the readme, use restview --long-description to preview changes.

Issues & Discussion

Please direct questions, comments, bugs, feature requests, etc. to: https://github.com/level12/keg/issues

Current Status

  • Stable in a relatively small number of production environments.

  • API is likely to change with smaller compatibility breaks happening more frequently than larger ones.

Changelog

0.6.6 released 2018-11-13

  • Add optional i18n support using morphi (d75a8fb)

  • Update pipenv dependencies to remove warning (b3b089e)

  • Pass through CLI invocation arguments and allow STDIN in CLI tests (bac2e3b)

0.6.5 released 2018-05-28

  • Update readme, start using pipenv, pin Flask < 1.0 (abdc9bf)

0.6.4 released 2018-01-09

  • when testing, don’t log to syslog by default (304a0a7)

0.6.3 released 2018-01-09

0.6.2 released 2017-12-19

  • db: get rid of code to replace session object (149b42c)

0.6.1 released 2017-11-16

  • fix quiet logging (e46fd2b)

  • a few small updates/fixes to readme (2044439)

0.6.0 released 2017-08-18

  • ADD: make CLIBase operate off current_app as last resort (1b358c1)

  • ADD: –quiet option to script options (6eb723f)

  • BREAKING CHANGE: adjust cli API on KegApp (af45880)

0.5.1 released 2017-08-15

  • ADD: mitigate CSRF bug in Flask-WTF (42a2e70)

  • ADD: config, init, and routing enhancements (cdfa901)

  • MAINT: upgrade to CircleCI 2.0 (60e3bfa)

0.5.0 released 2017-06-27

  • prep for pyp usage (23424b9)

  • Merge branch ‘logging-improvements’ (PR66)

0.4.1 - 2017-02-09

  • BUG: Properly quote pgsql identifiers during create (86852ad)

0.4.0 - 2016-12-19

  • BUG: Properly Update Keyring Config Data (7f1908f)

  • MSSQL dialect support (df7e89d)

  • MAINT: Refactor keyring to accept bytes (15bc04b)

  • MAINT: Remove deprecated flask hooks (4f7e2bf)

  • Remove unicode_literal futures (dc2fa85)

  • MAINT: Create windows build environment (983e040)

  • MAINT: Run CI with Docker (bc7a877)

  • Remove extra cp in readme (7e94815)

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

Keg-0.6.6.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

Keg-0.6.6-py2.py3-none-any.whl (59.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file Keg-0.6.6.tar.gz.

File metadata

  • Download URL: Keg-0.6.6.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.2

File hashes

Hashes for Keg-0.6.6.tar.gz
Algorithm Hash digest
SHA256 a00a5ff00305c66c88419a4705a637c6a0fa7de0c704da8150c7d148f240555a
MD5 c04ca33369386bb6e0c1a472a2a27a0e
BLAKE2b-256 70924bfe07d6bf0f20ddfcc3690ba8ba87e78b893406fbb995be018b1539560a

See more details on using hashes here.

File details

Details for the file Keg-0.6.6-py2.py3-none-any.whl.

File metadata

  • Download URL: Keg-0.6.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 59.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.2

File hashes

Hashes for Keg-0.6.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 11b0a0fd63792f9034078674b5a74ced719999a2e8fb41450bbbfe2e2f0c2de9
MD5 351d53451c5b8e1eb9178d77f9011e95
BLAKE2b-256 c6152a4cfab495ec23469c6ed9224a0613eeac066ab23467b747cf3527594ebf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page