extrapypi app¶
extrapypi.app module¶
Extrapypi app¶
Used to create application. This can be imported for wsgi file for uwsgi or gunicorn.
By default, application will look for a EXTRAPYPI_CONFIG env variable to load configuration file, but you can also pass a config parameter. The configuration files are loaded in the following order :
- Load default configuration
- If testing is set to True, load config_test.py and nothing else
- If config parameter is not None, use it and don’t load env variable config file
- If config parameter is None, try to load env variable
You can create a wsgi file like this for running gunicorn or uwsgi :
from extrapypi.app import create_app
app = create_app()
Or add any extra code if needed
-
extrapypi.app.
configure_app
(app, testing, config)¶ Set configuration for application
Configuration will be loaded in the following order:
- test_config if testing is True
- else if config parameter is not None we load it
- else if env variable for config is set we use it
-
extrapypi.app.
configure_extensions
(app)¶ Init all extensions
For login manager, we also register callbacks here
-
extrapypi.app.
configure_logging
(app)¶ Configure loggers
-
extrapypi.app.
create_app
(testing=False, config=None)¶ Main application factory
-
extrapypi.app.
register_blueprints
(app)¶ Register all views for application
-
extrapypi.app.
register_filters
(app)¶ Register additionnal jinja2 filters
extrapypi.config module¶
Extrapypi configuration¶
All settings present here can be override with your own configuration file using the EXTRAPYPI_CONFIG env variable.
If the env variable is not set, default settings will be used.
This file is a pure python file, that’s mean that you can also include python code in here, for example for packages location
Warning
For security reasons you should at least change the secret key
Note
If you use anything else than sqlite, you must install correct database drivers like psycopg2 or pymysql for example. Since we use SQLAlchemy you can use any compliant database, but we only test sqlite, mysql and postgresql
Note
You can also override all settings of flask extensions used by extra-pypi even if there are not here
For quickstart you can generate a sample configuration file using start
command like this
extrapypi start --filename myconfig.cfg
Generated file will have the following content
# Database connexion string
SQLALCHEMY_DATABASE_URI = "sqlite:///extrapypi.db"
# Update this secret key for production !
SECRET_KEY = "changeit"
# Storage settings
# You need to update at least packages_root setting
STORAGE_PARAMS = {
'packages_root': "/path/to/my/packages"
}
Configuration options
NAME | Description |
---|---|
BASE_DIR | Base directory, by default used by SQLALCHEMY_URI and PACKAGES_ROOT |
SQLALCHEMY_URI | SQLAlchemy connexion string |
DEBUG | Enable debug mode |
STATIC_URL | Url for static files |
SECRET_KEY | Secret key used for the application, you must update this |
STORAGE | Storage class name to use |
STORAGE_PARAMS | Storage class parameters, see specific storages documentation for more details |
DASHBOARD | You can disable dashboard if you set it to FALSE |
LOGGING_CONFIG | Logger configuration, using standard python dict config |
Defaut logging config look like this
LOGGING_CONFIG = {
'version': 1,
'root': {
'level': 'NOTSET',
'handlers': ['default'],
},
'formatters': {
'verbose': {
'format': '[%(asctime)s: %(levelname)s / %(name)s] %(message)s',
},
},
'handlers': {
'default': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'extrapypi': {
'handlers': ['default'],
'level': 'WARNING',
'propagate': False,
},
'alembic.runtime.migration': {
'handlers': ['default'],
'level': 'INFO',
'propagate': False
},
}
}