Backend¶
The backend itself consists of two major components: a login server and the API server. The login server is a Flask application which handles authentication for the user, generating tokens for the browser’s use when it hits API endpoints. The API server is a Klein application.
Prerequisites¶
The Python-based backend has a few basic prerequisites:
- A compatible operating system (we develop on OS X and deploy on Ubuntu)
- CPython 2.7+ or CPython 3.4+ (we develop and deploy with 2.7 but test against 3.4+)
- Development headers for
libffi. Installation: - With Homebrew on Mac:
brew install libffi - On Debian-based systems:
sudo apt-get install libffi-dev
- With Homebrew on Mac:
- Development headers for
Installation¶
We recommend using a Python virtualenv. Once you’ve set up an environment for Stethoscope, you
can install the backend and the bundled plugins easily using our Makefile:
make develop
Troubleshooting¶
Python 2.7.6 and pyenv¶
If installing on OSX 10.10+ for Python 2.7.6 or 2.7.7 using pyenv, you may encounter an error
(ld: file not found: python.exe; see this issue)
while installing Twisted. The workaround is to build a wheel for Twisted under 2.7.8, then
install the wheel into the 2.7.6 environment:
pyenv install 2.7.6
pyenv virtualenv 2.7.6 stethoscope
pyenv install 2.7.8
pyenv shell 2.7.8
pip wheel --wheel-dir=$TMPDIR/wheelhouse Twisted
pyenv shell stethoscope
pip install --no-index --find-links=$TMPDIR/wheelhouse Twisted
Configuration¶
Configuration for the login and API servers is separate, but share the same pattern (a series of
.py files loaded via Flask‘s configuration mechanism). In order (last file taking
precedence), the configurations are loaded from:
- The
defaults.pyfile from the package’s directory (e.g.,stethoscope/login/defaults.py). - An ‘instance’
config.pyfile (in the Flaskinstancesubdirectory, which can be changed usingSTETHOSCOPE_API_INSTANCE_PATHandSTETHOSCOPE_LOGIN_INSTANCE_PATH). - A file specified by the
STETHOSCOPE_API_CONFIGorSTETHOSCOPE_LOGIN_CONFIGenvironment variables. Examples of these are in theconfig/loginandconfig/apisubdirectories.
The minimum configuration file needs define only two variables: SECRET_KEY and
JWT_SECRET_KEY (see the included instance/config.py file for details).