Flask settings extension is similar to Django settings.
[](https://travis-ci.org/left-join/flask-settings)
[](https://coveralls.io/github/left-join/flask-settings?branch=master)
[](https://landscape.io/github/left-join/flask-settings/master)
# Installation
```bash
pip install flask-settings
```
# How to use
File app/settings/default.py
```python
from flask_settings import BasicConfig
class DefaultConfig(BasicConfig):
SQLALCHEMY_DATABASE_PROTOCOL = 'postgresql'
SQLALCHEMY_DATABASE_HOST = 'localhost'
SQLALCHEMY_DATABASE_PORT = 5432
SQLALCHEMY_DATABASE_USERNAME = 'postgres'
SQLALCHEMY_DATABASE_PASSWORD = 'postgres'
SQLALCHEMY_DATABASE_NAME = 'default'
@property
def SQLALCHEMY_DATABASE_URI(self):
# calculated constant
return '{protocol}://{username}:{password}@{host}:{port}/{db}'.format(
protocol=self.SQLALCHEMY_DATABASE_PROTOCOL,
username=self.SQLALCHEMY_DATABASE_USERNAME,
password=self.SQLALCHEMY_DATABASE_PASSWORD,
host=self.SQLALCHEMY_DATABASE_HOST,
port=self.SQLALCHEMY_DATABASE_PORT,
db=self.SQLALCHEMY_DATABASE_NAME)
```
File app/settings/development.py
```python
from app.settings.default import DefaultConfig
class DevelopmentConfig(DefaultConfig):
DEBUG = True
SQLALCHEMY_DATABASE_NAME = 'development'
```
File app/settings/testing.py
```python
from app.settings.default import DefaultConfig
class TestingConfig(DefaultConfig):
TESTING = True
SQLALCHEMY_DATABASE_NAME = 'testing'
```
File app/settings/production.py
```python
from app.settings.default import DefaultConfig
class ProductionConfig(DefaultConfig):
SQLALCHEMY_DATABASE_HOST = '10.0.0.1'
SQLALCHEMY_DATABASE_USERNAME = 'user'
SQLALCHEMY_DATABASE_PASSWORD = 'password'
SQLALCHEMY_DATABASE_NAME = 'production'
```
File app/application.py
```python
from flask import Flask
from flask_settings import Settings
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
settings = Settings(app)
db = SQLAlchemy(app)
db.create_all(app=app)
@app.route('/')
def index_page():
return 'database name: ' + settings.SQLALCHEMY_DATABASE_NAME
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
```
The global settings variable can be used in any module with application context:
```
from flask import Blueprint
from flask_settings.globals import settings
bp = Blueprint(__name__, __name__)
@bp.route('/')
def index_page():
return 'database name: ' + settings.SQLALCHEMY_DATABASE_NAME
```
Run application in development mode:
```bash
FLASK_SETTINGS="development" python app/application.py
```
Run application tests in testing mode:
```bash
FLASK_SETTINGS="testing" nosetests
```
Run application in production mode:
```bash
FLASK_SETTINGS="production" uwsgi --wsgi-file=app/application.py --callable=app --http=0.0.0.0:5000
```
Metadata
Release files for Flask-Settings 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-Settings-0.0.3.tar.gz | 3.9 kB | Without provenance | Details for Flask-Settings-0.0.3.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_Settings-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for Flask_Settings-0.0.3-py3-none-any.whl |
| Flask_Settings-0.0.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for Flask_Settings-0.0.3-py2.py3-none-any.whl |
Total release size: 16.7 kB
Release files / Flask-Settings-0.0.3.tar.gz
| Download URL | Flask-Settings-0.0.3.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c540c2927fa3a61ef70ed8d9ba92d0ea5f856053c5a8853a77a071da85baac80
|
|
BLAKE2b-256 checksum How to use checksums |
cfd1d1c08929726a640a4f9504c2287dc57997d59d1fb18a449426565ccef17b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Flask_Settings-0.0.3-py3-none-any.whl
| Download URL | Flask_Settings-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7236475d6ef5683f839f98303c740becd29e6e8ec49d56e64d7783f367bcaf0
|
|
BLAKE2b-256 checksum How to use checksums |
50ff04f66400a56cbfcbeb249c1a61988fa858218566d94f946e0ac4be0f100a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Flask_Settings-0.0.3-py2.py3-none-any.whl
| Download URL | Flask_Settings-0.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
673f6242688bd7066961faa6900b5eb7fe656a89094f753bc58ad0c7170469de
|
|
BLAKE2b-256 checksum How to use checksums |
ac0b4807a230d6aecbb6ebe5207fb974317b04f15502d7c6209a097ef416beae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for Flask-Settings 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.