Config¶
The Config class holds the contents of the configuration file.
Using in route handler¶
You can retrieve the contents of the configuration file by receiving config
as an argument in your route handler.
from pykour import Pykour, Config
app = Pykour(config=Config('config.yaml'))
@app.get('/')
def index(config: Config):
return { 'message': config.get('message') }
Logging settings¶
Logging settings are configured using the pykour.logging
key.
Logging level setting¶
Logging levels are set using the level
key.
pykour:
logging:
level: INFO, DEBUG
Pykour does not filter by level in general, but by enumerating the levels to be covered.
In this example, in addition to the explicitly specified INFO
and DEBUG
logs, the access log is also output.
Database Settings¶
Database settings are configured using the pykour.datasource
key.
Database type setting¶
Database type is set using the type
key.
pykour:
datasource:
type: sqlite
Settings database connection information¶
Use host
, db
, username
, and password
to set database connection information.
pykour:
datasource:
type: mysql
host: localhost
db: test
username: root
password: password
The available settings are as follows:
host
: Database hostnamedb
: Database nameusername
: Usernamepassword
: Password
connection pool settings¶
Use the pool
key to set up a connection pool.
pykour:
datasource:
type: mysql
host: localhost
db: test
username: root
password: password
pool:
max-connections: 10
To set up a connection pool, specify the maximum pool size with the max-connections
key.