Building out an opinionated Falcon REST API for a movie recommendation project.
alysivji, updated
🕥
2022-01-21 19:27:14
Falcon Batteries Included

This opinionated project demonstrates how use Falcon and various Python libraries to build a scalable REST API for a movie recommendation website.
Table of Contents
Design
Use the best tool for the job at hand.
- Most of the CRUD logic is in controllers, but if we have to do perform multiple tasks for an endpoint, a process is kicked off.
- Took inspiration from Twelve-Factor App
Development Workflow
- Development environment leverages Docker-Compose to replicate production environment
Makefile
provides common operations for development
- pre-commit hooks identify comomn code review issues before submission
- CI pipeline is triggered on push to branch and PR creation
Getting Started
make up
- Create virtual environment on local machine,
pip install -r requirements_dev.txt
to install dependencies locally
- Point IDE's
PYTHONPATH
to the python
instance in the virtual environment from above to get autocomplete and other tooling working
- Install
pre-commit
on your development machine
pre-commit install
will run existing hook scripts (from .pre-commit-config.yaml
)
Server available at http://0.0.0.0:7000/
Search Notes
- Implemented in console in console only, TODO: add search endpoint
python
Movie.reindex()
Movie.search("top gun", page=1, per_page=5)
Python Best Practices
Batteries
Asynchronous Task Queue
Authentication
Continuous Integration, Continouous Delivery (CICD)
Documentation
Full-Text Search
ORM (SQLAlchemy)
- Follow pattern described in SQLAlchemy docs
- Load database (well, declarative base) into the request object
- Remove database from request before sending response
- Migrations with Alembic
Profiler
console
USAGE:
py-spy --duration <duration> --pid <pid> --rate <rate>
Security
Serialization / Deserialization
- Marshmallow to serialize objects into JSON (response) and deserialize JSON into object (request)
- webargs to parse requests arguments (query string)
toasted-marshmallow
has 10x performance, investigate
Testing
- pytest
- Functional tests via tavern
- Works locally and not in drone (currently excluded from CI check)
- Either write a plugin to have Tavern hit Falcon test API or use Jenkins
Issues
opened on 2022-01-21 19:27:13 by dependabot[bot]
Bumps ipython from 6.5.0 to 7.16.3.
Commits

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/alysivji/falcon-batteries-included/network/alerts).
opened on 2021-04-07 21:29:31 by dependabot[bot]
Bumps webargs from 5.5.1 to 5.5.3.
Changelog
Sourced from webargs's changelog.
5.5.3 (2020-01-28)
Bug fixes:
- :cve:
CVE-2020-7965
: Don't attempt to parse JSON if request's content type is mismatched.
5.5.2 (2019-10-06)
Bug fixes:
- Handle
UnicodeDecodeError
when parsing JSON payloads (:issue:427
).
Thanks :user:lindycoder
for the catch and patch.
Commits
29b6a16
Bump version and update changelog
74fada6
Skip JSON parsing if Content-Type is mismatched
f1ae764
Bump version and update changelog
6347b4b
Handle decoding errors like json decode errors (#428)
fb8ff11
Run pre-commit autoupdate
f2db6bc
Merge pull request #429 from marshmallow-code/dependabot/pip/mypy-0.730
211c442
Bump mypy from 0.720 to 0.730
- See full diff in compare view

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/alysivji/falcon-batteries-included/network/alerts).
opened on 2021-03-25 22:01:32 by dependabot[bot]
Bumps pyyaml from 5.1.2 to 5.4.
Changelog
Sourced from pyyaml's changelog.
5.4 (2021-01-19)
5.3.1 (2020-03-18)
- yaml/pyyaml#386 -- Prevents arbitrary code execution during python/object/new constructor
5.3 (2020-01-06)
5.2 (2019-12-02)
- Repair incompatibilities introduced with 5.1. The default Loader was changed,
but several methods like add_constructor still used the old default
yaml/pyyaml#279 -- A more flexible fix for custom tag constructors
yaml/pyyaml#287 -- Change default loader for yaml.add_constructor
yaml/pyyaml#305 -- Change default loader for add_implicit_resolver, add_path_resolver
- Make FullLoader safer by removing python/object/apply from the default FullLoader
yaml/pyyaml#347 -- Move constructor for object/apply to UnsafeConstructor
- Fix bug introduced in 5.1 where quoting went wrong on systems with sys.maxunicode <= 0xffff
yaml/pyyaml#276 -- Fix logic for quoting special characters
- Other PRs:
yaml/pyyaml#280 -- Update CHANGES for 5.1
Commits
58d0cb7
5.4 release
a60f7a1
Fix compatibility with Jython
ee98abd
Run CI on PR base branch changes
ddf2033
constructor.timezone: _copy & deepcopy
fc914d5
Avoid repeatedly appending to yaml_implicit_resolvers
a001f27
Fix for CVE-2020-14343
fe15062
Add 3.9 to appveyor file for completeness sake
1e1c7fb
Add a newline character to end of pyproject.toml
0b6b7d6
Start sentences and phrases for capital letters
c976915
Shell code improvements
- Additional commits viewable in compare view

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/alysivji/falcon-batteries-included/network/alerts).