usage: openfisca serve [-h] [-c COUNTRY_PACKAGE] [-e [EXTENSIONS ...]]
[-r [REFORMS ...]] [-p PORT]
[--tracker-url TRACKER_URL]
[--tracker-idsite TRACKER_IDSITE]
[--tracker-token TRACKER_TOKEN]
[--welcome-message WELCOME_MESSAGE]
[-f CONFIGURATION_FILE]
country package to use. If not provided, an automatic detection will be attempted by scanning the python packages installed in your environment which name contains the word “openfisca”.
extensions to load
reforms to apply to the country package
port to serve on (use –bind to specify host and port)
tracking service url
tracking service id site
tracking service authentication token
welcome message users will get when visiting the API root
configuration file
openfisca serve
uses gunicorn
under the hood. In addition to the arguments listed above, you can use any gunicorn
arguments when running openfisca serve
(e.g. --reload
, --workers
, --timeout
, --bind
).
See:
gunicorn --help
openfisca serve --country-package openfisca_france
openfisca serve --country-package openfisca_france --extensions openfisca_paris
openfisca serve --country-package openfisca_france --reforms openfisca_france.reforms.plf2015.plf2015
You can setup openfisca serve
using a configuration file. Be careful as parameters with a ‘-’ in their name on command line change to an ‘_’ when used from the config file. See this example of configuration:
config.py:
port = 4000
workers = 4
bind = '0.0.0.0:{}'.format(port)
country_package = 'openfisca_france'
extensions = ['openfisca_paris']
Command line:
openfisca serve --configuration-file config.py
If for any reason you nedd to run gunicorn
directly, you can. See this example of gunicorn
application:
app.py:
from openfisca_core.scripts import build_tax_benefit_system
from openfisca_web_api.app import create_app
country_package = 'openfisca_france'
extensions = ['openfisca_paris']
reforms = ['openfisca_france.reforms.plf2015.plf2015']
tax_benefit_system = build_tax_benefit_system(
country_package_name = country_package,
extensions = extensions,
reforms = reforms,
)
application = create_app(tax_benefit_system)
Command line:
gunicorn app --bind 0.0.0.0:4000 --workers=4