Flample is a Python Flask Sample Restful API.
Sqlite DB is used for storing data. Sqlalchemy is used to help with the queries. I have used a service layer which is an internal API of this system. On top of this internal API, two applications have been implemented.
- Restful API
- Frontend
Restful API is used for CRUD operations. Frontend application is used for serving static files(CSS, JS, HTML) and is also responsible for routing as I have not used any frontend routing solution. All API endpoints are hidden behind authentication. Currently using cookies based session and authentication and API can be tested in browser easily for now. We can easily switch to Token based authentication (Will do it when have time).
No major frontend framework used due to shortage of time, just basic jquery. Dashboard.js is reponsible for doing all ajax requests to the backend API.
On the backend, functional tests are added for testing all the endpoints. I am using
- Pytest
- Factory boy
At the bare minimum you'll need the following for your development environment:
The following assumes you have all of the recommended tools listed above installed.
$ git clone git@github.com:syedwaseemjan/Flample.git
$ cd Flample
$ mkdir flample_virtualenv
$ virtualenv flample_virtualenv
$ source flample_virtualenv/bin/activate
$ pip install -r requirements.txt
$ flask create_db
$ flask create_admin
$ pytest -v
$ python runserver.py
Visit http://127.0.0.1:5000
Username: admin@flample.com
Password: test123
Flample employs automated checkers to make sure that all contributions follow basic conventions.
black
: to check the code style.flake8
: to check for PEP-8, McCabe complexity,isort
violations, pyflakes checks (such as unused imports/variables, etc).
Any pull request that violates any of these convention will fail and must be fixed before asking for a code review.
In order to avoid submitting failing PRs, make sure to install pre-commit hooks configured in this repo by running:
$ pip install pre-commit
$ pre-commit install
Now, every time you try to commit your code black
will automatically reformat it, isort
will
automatically sort your imports and flake8
will look for and report any common issues found on
the code you are trying to commit.
There are a few commands to help you out with the task of keeping your code compliant with BriteLines standards:
- Run
black
andflake8
checkers:
$ flake8
- Fix all the code style and import order issues:
$ black --check .