Config
Config holds all settings needed to connect and authenticate with a Matrix homeserver. It can be loaded from a YAML file or constructed directly with keyword arguments. At minimum, a homeserver URL and one authentication method (password or access token) are required.
from matrix.config import Config
# Load from a YAML file
config = Config(config_path="config.yml")
# Or configure manually
config = Config(
homeserver="https://matrix.org",
username="@mybot:matrix.org",
password="hunter2",
)
matrix.config.Config
Config(
config_path=None,
*,
homeserver=None,
username=None,
password=None,
token=None,
prefix=None
)
Configuration handler for Matrix client settings.
Manages all settings required to connect and authenticate with a Matrix homeserver. Configuration can be loaded from a YAML file or provided directly via constructor parameters. At least one authentication method must be provided.
Example
# Load from file
config = Config(config_path="path/to/config..yaml")
# Manual configuration
config = Config(username="@bot:matrix.org", password="secret")
Initialize the bot configuration.
Loads configuration from a YAML file if provided, otherwise uses the provided parameters directly. At least one of password or token must be supplied.
Example
config = Config(
username="@bot:matrix.org",
password="secret",
prefix="!",
)
Source code in matrix/config.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
homeserver
instance-attribute
homeserver = homeserver or 'https://matrix.org'
username
instance-attribute
username = username
password
instance-attribute
password = password
token
instance-attribute
token = token
prefix
instance-attribute
prefix = prefix or '!'
load_from_file
load_from_file(config_path)
Load Matrix client settings from a YAML config file.
Supports environment variable substitution via EnvYAML. Values in the YAML file can reference environment variables using ${VAR} syntax.
Example
config = Config()
config.load_from_file("path/to/config.yaml")
Source code in matrix/config.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
get
get(key, *, section=None, default=None)
Access a config value by key, optionally scoped to a section.
Example
config.get(key="main_channel", section="bot")
config.get(key="log_level", default="INFO")
Source code in matrix/config.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |