Python Configuring an Application in Sanic Library

Python Configuring an Application in Sanic Library


In the previous article we introduce Sanic library to you and how to install it. A simple hello world application was also created. If you have not checked that article please check it using  the following link Introduction to Sanic Library

In this article we are going to talk about how to configure your applications to meet your specific needs using Sanic Library.

Basic Configuration:

Configuration in Sanic is done using the config attribute of the app object. The configuration object can be modified either using dot-notation or a dictionary.

Using dot notation:

Using dictionary:

We can also use  update method of config to set several values at once.

Note that in general the convention is to only have Uppercase configuration parameters.

Loading Configuration:

If you already have or want to use some predefined configuration then you can use the following methods for setting the configuration.

Using Environment Variables:
Variables defined with the prefix SANIC will be applied to the sanic config.

Using File:
If you have a configuration file named then you can use the method app.upload_config()


In this article we saw how we can configure our applications. We also learnt how to load the configuration using Environment Variables or from a configuration file. In further articles we will introduce more exciting features of Sanic Library.
Please look forward to other articles on Sanic.