Skip to content

Commit f21a59a

Browse files
committed
Docs has been modified, contributers are welcome pls read CONTRIBUTING.md
1 parent 3f21e99 commit f21a59a

File tree

15 files changed

+554
-47
lines changed

15 files changed

+554
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__/
66
# C extensions
77
*.so
88
.vscode/
9+
app.py
910
# Distribution / packaging
1011
.Python
1112
build/

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Contributing to fastapi-mqtt
2+
=========================================
3+
4+
We welcome contributions to [fastapi-mqtt](https://github.com/sabuhish/fastapi-mqtt)
5+
6+
Issues
7+
------
8+
9+
Feel free to submit issues and enhancement requests.
10+
11+
[Fatapi-MQTT Issues](https://github.com/sabuhish/fastapi-mqtt/issues)
12+
13+
Contributing
14+
------------
15+
16+
Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.
17+
18+
1. **Fork** the repo on GitHub
19+
2. **Clone** the project to your own machine
20+
3. **Commit** changes to your own branch
21+
4. **Push** your work
22+
5. Submit a **Pull request** so that we can review your changes
23+
24+
25+
### Before get in to the repo and type:
26+
27+
28+
```sh
29+
$ bash fastapi-mqtt.sh install
30+
$ source .venv/bin/activate
31+
$ cat app.py
32+
33+
34+
```
35+
36+
```sh
37+
uvicorn app:app --port 8000 --reload
38+
39+
```
40+
41+
42+
43+
NOTE: Be sure to merge the latest from "upstream" before making a pull request!

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ MQTT specification avaliable with help decarator methods using callbacks:
4343

4444

4545

46-
### Guide
46+
### 🕹 Guide
47+
4748

4849
```python
4950
from fastapi import FastAPI

docs/contribute.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Contributing to fastapi-mqtt
2+
=========================================
3+
4+
We welcome contributions to [fastapi-mqtt](https://github.com/sabuhish/fastapi-mqtt)
5+
6+
Issues
7+
------
8+
9+
Feel free to submit issues and enhancement requests.
10+
11+
[Fatapi-MQTT Issues](https://github.com/sabuhish/fastapi-mqtt/issues)
12+
13+
Contributing
14+
------------
15+
Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.
16+
17+
1. **Fork** the repo on GitHub
18+
2. **Clone** the project to your own machine
19+
3. **Commit** changes to your own branch
20+
4. **Push** your work
21+
5. Submit a **Pull request** so that we can review your changes
22+
23+
24+
### Before get in to the repo and type:
25+
26+
27+
```sh
28+
$ bash fastapi-mqtt.sh install
29+
$ source .venv/bin/activate
30+
$ cat app.py
31+
```
32+
33+
```sh
34+
uvicorn app:app --port 8000 --reload
35+
```
36+
37+
38+
39+
NOTE: Be sure to merge the latest from `upstream` before making a pull request!

docs/example.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
4+
### Full example
5+
```python
6+
7+
@app.on_event("startup")
8+
async def startapp():
9+
await mqtt.connection()
10+
11+
@app.on_event("shutdown")
12+
async def shutdown():
13+
await mqtt.client.disconnect()
14+
15+
@mqtt.on_connect()
16+
def connect(client, flags, rc, properties):
17+
mqtt.client.subscribe("/mqtt") #subscribing mqtt topic
18+
print("Connected: ", client, flags, rc, properties)
19+
20+
@mqtt.on_message()
21+
async def message(client, topic, payload, qos, properties):
22+
print("Received message: ",topic, payload.decode(), qos, properties)
23+
return 0
24+
25+
@mqtt.on_disconnect()
26+
def disconnect(client, packet, exc=None):
27+
print("Disconnected")
28+
29+
@mqtt.on_subscribe()
30+
def subscribe(client, mid, qos, properties):
31+
print("subscribed", client, mid, qos, properties)
32+
33+
34+
@app.get("/")
35+
async def func():
36+
await fast_mqtt.publish("/mqtt", "Hello from Fastapi") #publishing mqtt topic
37+
38+
return {"result": True,"message":"Published" }
39+
```

docs/getting-started.md

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
1-
## Mad Migration
1+
### 🕹 Guide
22

3-
## some
4-
#### Example
5-
##### assa
3+
After installing the module you setup your `FastApi` app:
4+
5+
Main classes are ```FastMQTT``` and ```MQQTConfig```
6+
7+
8+
9+
```python
10+
from fastapi import FastAPI
11+
from fastapi_mqtt import FastMQTT, MQQTConfig
12+
13+
app = FastAPI()
14+
15+
mqtt_config = MQQTConfig()
16+
17+
mqtt = FastMQTT(
18+
config=mqtt_config
19+
)
20+
21+
```
22+
23+
### ```MQQTConfig``` class
24+
class has following attributes
25+
26+
- host : To connect MQQT broker, defaults to localhost
27+
- port : To connect MQQT broker, defaults to 1883
28+
- ssl : if given and not false, a SSL/TLS transport is created (by default a plain TCP transport is created)
29+
If ssl is a ssl.SSLContext object, this context is used to create the transport; if ssl is True, a default context returned from ssl.create_default_context() is used.
30+
- keepalive : Maximum period in seconds between communications with the broker.
31+
If no other messages are being exchanged, this controls the rate at which
32+
the client will send ping messages to the broker the keepalive timeout value for the client. Defaults to 60 seconds.
33+
- username : username for authentication, defaults to None
34+
- password : password for authentication, defaults to None
35+
- version : MQTT broker version to use, defaults to MQTTv50.
36+
According to gmqtt.Client if your broker does not support 5.0 protocol version and responds with proper CONNACK reason code, client will downgrade to 3.1 and reconnect automatically.
37+
- reconnect_retries
38+
- reconnect_delay
39+
40+
reconnect_retries && reconnect_delay : By default, connected MQTT client will always try to reconnect in case of lost
41+
connections. Number of reconnect attempts is unlimited.
42+
If you want to change this behaviour pass reconnect_retries and reconnect_delay with its values.
43+
For more info: # https://github.com/wialon/gmqtt#reconnects
44+
45+
Last three parameters is used after client disconnects abnormally
46+
param :: will_message_topic : Topic of the payload
47+
param :: will_message_payload : The payload
48+
param :: will_delay_interval : Delay interval
49+
50+
- will_message_topic
51+
- will_message_payload
52+
- will_delay_interval
53+
54+
### ```FastMQTT``` client
55+
56+
client object to establish connection parametrs beforeconnect and manipulate MQTT service.
57+
### ```FastMQTT``` params
58+
client has following parametrs. The class object holds session information necesseary to connect MQTT broker.
59+
<!--
60+
61+
62+
""
63+
64+
param :: optimistic_acknowledgement : #TODO more info needed
65+
type :: optimistic_acknowledgement: bool -->
66+
67+
- config : MQQTConfig config class
68+
- client_id : unique identfiyer for connection to MQQT broker
69+
- clean_session : The clean session flag tells the broker whether the client wants to establish \
70+
a persistent session or not. In a persistent session clean_session = False, the broker stores all subscriptions for the client and \
71+
all missed messages for the client that subscribed with a Quality of Service (QoS) level 1 or 2. \
72+
If the session is not persistent (clean_session = True),the broker does not store anything for the client and \
73+
purges all information from any previous persistent session.The client_id that the client provides when it establishes connection to the broker identifies the session.,
74+
- optimistic_acknowledgement
675

7-
Cupcake indexer is a snazzy new project for indexing small cakes.
876

977

10-
*Above: Cupcake indexer in progress*

docs/index.md

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
<!-- ## Mad Migration
1+
# FastApi-MQTT
22

3-
[![MIT licensed](https://img.shields.io/github/license/marlin-dev/startapp)](https://raw.githubusercontent.com/marlin-dev/startapp/master/LICENSE)
4-
[![GitHub stars](https://img.shields.io/github/stars/marlin-dev/startapp.svg)](https://github.com/marlin-dev/startapp/stargazers)
5-
[![GitHub forks](https://img.shields.io/github/forks/marlin-dev/startapp.svg)](https://github.com/marlin-dev/startapp/network)
6-
[![GitHub issues](https://img.shields.io/github/issues-raw/marlin-dev/startapp)](https://github.com/marlin-dev/startapp/issues)
7-
[![Downloads](https://pepy.tech/badge/startapp)](https://pepy.tech/project/startapp)
3+
## Extension
4+
MQTT is a lightweight publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments.
5+
Fastapi-mqtt is the client for working with MQTT.
86

7+
For more information about MQQT, please refer to here: [MQTT](mqtt.md)
98

10-
CLI tool and Packgae provide easy and fast migration from one database to another database by specifiying its fields and types.
9+
Fatapi-mqtt wraps around [gmqtt](https://github.com/wialon/gmqtt) module. Gmqtt Python async client for MQTT client implementation.
10+
Module has support of MQTT version 5.0 protocol
1111

12-
Tool has been made by Mad Team for other tools check our [Organization](https://github.com/MadMigrationTeam).
12+
## Badges
1313

14-
Full code can be found on [GitHub Repo](https://github.com/MadMigrationTeam/mad-migration).
14+
[![MIT licensed](https://img.shields.io/github/license/sabuhish/fastapi-mqtt)](https://raw.githubusercontent.com/sabuhish/fastapi-mqtt/master/LICENSE)
15+
[![GitHub stars](https://img.shields.io/github/stars/sabuhish/fastapi-mqtt.svg)](https://github.com/sabuhish/fastapi-mqtt/stargazers)
16+
[![GitHub forks](https://img.shields.io/github/forks/sabuhish/fastapi-mqtt.svg)](https://github.com/sabuhish/fastapi-mqtt/network)
17+
[![GitHub issues](https://img.shields.io/github/issues-raw/sabuhish/fastapi-mqtt)](https://github.com/sabuhish/fastapi-mqtt/issues)
18+
[![Downloads](https://pepy.tech/badge/fastapi-mqtt)](https://pepy.tech/project/fastapi-mqtt)
1519

20+
## Available Features
1621

17-
Please see the [License](license.md) for further details.
22+
MQTT specification avaliable with help decarator methods using callbacks:
1823

24+
- ```on_connect() ```
25+
- ```on_disconnect() ```
26+
- ```on_subscribe() ```
27+
- ```on_message() ```
1928

20-
21-
## Dependencies
22-
23-
sqlalchmey
24-
mysql-client
25-
26-
```
27-
Fenced code blocks are like Standard
28-
29-
```
30-
31-
32-
```python
33-
if not (credentials.username == "stanleyjobson") or not (credentials.password == "swordfish"):
34-
# Return some error
35-
...
36-
```
37-
38-
* Import `HTTPBasic` and `HTTPBasicCredentials`.
39-
* Create a "`security` scheme" using `HTTPBasic`.
40-
* Use that `security` with a dependency in your *path operation*.
41-
* It returns an object of type `HTTPBasicCredentials`:
42-
* It contains the `username` and `password` sent. -->
29+
Base Settings available with ```pydantic``` class:
30+
31+
- ```Authetication``` to broker with credentials
32+
- ```unsubscribe``` certain topics and ```publish``` to certain topics

docs/install.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
## Using Pip
1+
## Using pip
22

33
```bash
4+
python3 -m venv .venv
5+
6+
source .venv/bin/activate
7+
48
pip install fastapi-mqtt
59
```
610

0 commit comments

Comments
 (0)