A web framework built on Flask & SQLAlchemy. Somewhere North of Flask but South of Django.
Project description
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 Prority
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_profilewas passed intomyapp.init()as an argument, use it as the selected profile. The--profilecli 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 byMyApp.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 variableDEFAULT_PROFILE. If found, use the value from the file with highest priority.
Keg Development
To develop on keg, begin by running our 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 tox
You can then examine tox.ini for insights into our development process. In particular, we:
use
py.testfor testing (and coverage analysis)use
flake8for lintingstore
piprequirements files inrequirements/cache wheels in
requirements/wheelhousefor faster & more reliable CI builds
Dependency Management
Adding a dependency involves:
Adding the dependency to one of the requirements files in
requirements/.Running
wheelhouse build
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
Very Alpha, expect changes.
Changelog
0.5.0 released 2017-06-27
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)
0.3.1 released 2016-03-17
Fixed 0.3.0 build where readme wouldn’t install correctly
Cleaned up repo which had a coverage report commited
Added a new build environment
0.3.0 released 2015-09-16
better pypi classifiers
use Wheelhouse for dependency management
Add tests for
BaseViewauto-assign feature.Add an asset manager.
Templates can now use the
assets_includetag in Jinja templates to automatically include the content of a file with the same base name but a ‘css’ or ‘js’ suffix. Seekeg_apps/templating/templates/assets_in_template.htmlfor example.Templates can now use the
assets_contenttag to include content with a specific suffix. Seekeg_apps/templating/templates/assets_content.htmlfor example.
Adjust DB clearing so that
prep_empty()is called after during db_clear() and not onlydb_init_with_clear().Fix selection of configuration profile so that the ordering is consitent for app instances created by
testing_prep()andinvoke_command().
Backwards incompatibility notes:
In the unlikely event you were relying on
keg.db:DatabaseManager.prep_empty()in a non-default way, you may have some adjustments to make.myapp.config_profilehas been removed. Usemyapp.config.profileinstead.the signature of
MyApp()andmyapp.init()has changed.
development version: 2015-05-25
Remove
Keg.testing_cleanup(): wasn’t really neededFix db init when SQLALCHEMY_BINDS config option not present but DB feature enabled
Adjust the way Jinja filters and globals are handled. Keg will now process
.template_filtersand.template_globals(both should be dicts) if defined on an app.add signals and commands for database init and clearing
new
Keg.visit_modulesattribute & related functionality to have Keg load Python modules after the app has been setup.
BC changes required:
if you were using
Keg.testing_cleanup()explicitly, remove it.If using
.jinja_filterson your app, rename to.template_filters
development version: 2015-05-23
Making changes to the way database interactions are handled.
Move
keg.sqlalchemytokeg.dbkeg.Keg’ssqlalchemy_*properties have been renamed, seedb_*variables instead.All database management is being delegated to an application specific instance of
keg.db.DatabaseManager. The class used to manage the db is selected bykeg.Keg.db_manager_clsso custom db management functionality for an app can be easily implemented by overriding that method on an app and specifying a different DB manager.keg.db.DatabaseManageris multi-connection aware using the “bind” functionality adopted by Flask-SQLAlchemy.Added
keg_apps.dbapplication and related tests.Added
keg.db.dialect_opsto manager RDBMS specific database interactions.Move
clear_db()functionality intokeg.db.dialect_opsAdd concept of dialect options to Keg config handling (
KEG_DB_DIALECT_OPTIONS). The PostgreSQL dialect handles the optionpostgresql.schemasto facilitate the testing setup of multiple schemas in a PostgreSQL database. Seekeg_apps.db.configfor example usage.
BC changes required:
On your app, if you have
sqlalchemy_enabledset, change it todb_enabledIf importing from
keg.sqlalchemychange tokeg.db.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Keg-0.5.0.tar.gz.
File metadata
- Download URL: Keg-0.5.0.tar.gz
- Upload date:
- Size: 45.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbd3a95ce0b230cd2859ad288374ed13f603c9bf4a252bd821285e2f33834b36
|
|
| MD5 |
11d22450dd5f0c4d607c05ee7a920a0e
|
|
| BLAKE2b-256 |
ef0566ea4a5588ee8854e0a81ed204356c098597ae3d77832dfca8f927017222
|
File details
Details for the file Keg-0.5.0-py2.py3-none-any.whl.
File metadata
- Download URL: Keg-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 64.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c242a14ff28b66eddbec144cc295fa05b799be609493c1467e2ebd494028c42e
|
|
| MD5 |
0498b0a62cd68f70f2b4ba1176998460
|
|
| BLAKE2b-256 |
5fe0c53417b881e7c54a12c8f70a105f92bfe7dcd4c3529fd1d5804168f6118d
|