Skip to main content
# flask-settings
Flask settings extension is similar to Django settings.

[![Build Status](https://travis-ci.org/left-join/flask-settings.svg?branch=master)](https://travis-ci.org/left-join/flask-settings)
[![Coverage Status](https://coveralls.io/repos/github/left-join/flask-settings/badge.svg?branch=master)](https://coveralls.io/github/left-join/flask-settings?branch=master)
[![Code Health](https://landscape.io/github/left-join/flask-settings/master/landscape.svg?style=flat)](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)

Source distribution for Flask-Settings 0.0.3
File Size Uploaded
Flask-Settings-0.0.3.tar.gz 3.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for Flask-Settings 0.0.3
File Interpreter ABI Platform
Flask_Settings-0.0.3-py3-none-any.whl Python 3 none any Details
Flask_Settings-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.0.3 This release

3 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page