2025-05-21 13:53:46 +00:00
# Broker API reference
2015-11-06 22:02:19 +00:00
2025-05-21 13:53:46 +00:00
The `amqtt.broker.Broker` class provides a complete MQTT 3.1.1 broker implementation. This class allows Python developers to embed a MQTT broker in their own applications.
2015-11-13 21:07:58 +00:00
2025-05-21 13:53:46 +00:00
## Usage example
2015-11-13 21:07:58 +00:00
The following example shows how to start a broker using the default configuration:
2025-05-21 13:53:46 +00:00
```python
2025-06-09 18:32:55 +00:00
--8< -- " samples / broker_simple . py "
2025-05-21 13:53:46 +00:00
```
2025-05-28 11:45:12 +00:00
This will start the broker and let it run until it is shutdown by `^c` .
2025-05-21 13:53:46 +00:00
## Reference
### Broker API
The `amqtt.broker` module provides the following key methods in the `Broker` class:
- `start()` : Starts the broker and begins serving
- `shutdown()` : Gracefully shuts down the broker
### Broker configuration
2025-05-28 11:45:12 +00:00
The `Broker` class's `__init__` method accepts a `config` parameter which allows setup of default and custom behaviors.
2025-05-21 13:53:46 +00:00
2025-05-28 11:45:12 +00:00
Details on the `config` parameter structure is a dictionary whose structure is identical to yaml formatted file[^1]
used by the included broker script: [broker configuration ](broker_config.md )
2025-05-22 01:59:12 +00:00
::: amqtt.broker.Broker
2019-01-04 17:29:48 +00:00
2025-05-21 13:53:46 +00:00
[^1]: See [PyYAML ](http://pyyaml.org/wiki/PyYAMLDocumentation ) for loading YAML files as Python dict.