How to use
In this guide you will learn how use Kivy Reloader for your projects.
Project structure¶
Select the app structure below according to your experience level: beginner or advanced.
If you are a beginner in Kivy, this is how to hot reload only one file: main.py
.
Create a basic project structure by executing these commands on your terminal:
// Create a folder for your project
$ mkdir kivyschool-hello
// Go to the project folder and initialize it with uv
$ cd kivyschool-hello
$ uv init
// Add kivy-reloader to your project
$ uv add kivy-reloader
Your project folder should look like this:
kivyschool-hello
├── main.py
├── pyproject.toml
├── README.md
└── uv.lock
Open main.py
file and paste this code:
main.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
How to setup Kivy Reloader¶
In the project folder, type in the terminal uv run kivy-reloader init
.
$ uv run kivy-reloader init
This is going to create two files on your project folder:
- kivy-reloader.toml: Configuration file for Kivy Reloader.
- buildozer.spec: Buildozer configuration file already set up for Kivy Reloader.
This is the kivy-reloader.toml
that has been created on your project folder.
kivy-reloader.toml
kivy-reloader.toml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 74 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
This file has many options that you can customize. The most important ones are:
- HOT_RELOAD_ON_PHONE: Enable/disable hot-reload on your phone (default:
true
). - FULL_RELOAD_FILES: List of files that trigger a full app restart when changed (default:
["main.py"]
). - WATCHED_FOLDERS_RECURSIVELY: Specifies the folders to monitor for changes recursively. By default, it is set to
["."]
, which means all files and folders in the project directory are watched. - STREAM_USING: Connection method, either
"USB"
or"WIFI"
(wireless requires initial cable connection) (default:"USB"
).
All other options are explained in the comments of the file. Every option has a default value, so you can remove all lines and only keep the ones you want to customize. For example:
kivy-reloader.toml | |
---|---|
1 2 3 4 5 6 |
|
This is the recommended way of structuring your app. Create a basic project structure by executing these commands on your terminal:
// Create a folder for your project
$ mkdir kivyschool-hello
// Go to the project folder and initialize it with uv
$ cd kivyschool-hello
$ uv init
// Add kivy-reloader to your project
$ uv add kivy-reloader
-
Create a folder called
hello_world
. -
Inside the
hello_world
folder, create a file calledapp.py
. -
Inside the
hello_world
folder, create a folder calledscreens
. -
Inside the
screens
folder, create two files:main_screen.kv
andmain_screen.py
Your project folder should look like this:
kivyschool-hello
├── hello_world
│ ├── app.py
│ └── screens
│ ├── main_screen.py
│ └── main_screen.kv
├── main.py
├── pyproject.toml
├── README.md
└── uv.lock
main.py | |
---|---|
1 2 3 4 5 6 |
|
hello_world/app.py | |
---|---|
1 2 3 4 5 6 7 8 |
|
hello_world/screens/main_screen.kv | |
---|---|
1 2 3 4 5 |
|
hello_world/screens/main_screen.py | |
---|---|
1 2 3 4 5 6 7 8 |
|
How to setup Kivy Reloader¶
In the project folder, type in the terminal uv run kivy-reloader init
.
$ uv run kivy-reloader init
This is going to create two files on your project folder:
- kivy-reloader.toml: Configuration file for Kivy Reloader.
- buildozer.spec: Buildozer configuration file already set up for Kivy Reloader.
This is the kivy-reloader.toml
that has been created on your project folder.
kivy-reloader.toml
kivy-reloader.toml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 74 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
This file has many options that you can customize. The most important ones are:
- HOT_RELOAD_ON_PHONE: Enable/disable hot-reload on your phone (default:
true
). - FULL_RELOAD_FILES: List of files that trigger a full app restart when changed (default:
["main.py"]
). - WATCHED_FOLDERS_RECURSIVELY: Specifies the folders to monitor for changes recursively. By default, it is set to
["."]
, which means all files and folders in the project directory are watched. - STREAM_USING: Connection method, either
"USB"
or"WIFI"
(wireless requires initial cable connection) (default:"USB"
).
All other options are explained in the comments of the file. Every option has a default value, so you can remove all lines and only keep the ones you want to customize. For example:
kivy-reloader.toml | |
---|---|
1 2 3 4 5 6 |
|
How to Use Kivy Reloader¶
Step 1: Run the application on your computer¶
$ uv run main.py
This is going to start your Kivy app on your computer with Kivy Reloader in the background. The hot reload feature is activated automatically, it starts tracking the state of your files and folders.
Step 2: Run the application on your Android device¶
On a second terminal, run the following command to deploy the app to your Android device:
$ uv run kivy-reloader run
Select the first option and Buildozer will compile the app (create a .apk
file) and deploy it on your phone. Once the app is running on your phone, the hot reload will be already working.
Step 3: Start developing with hot reload¶
When you change and save any file in the folders that are being watched, Kivy Reloader syncs and reloads the app on your computer and on your Android device (if connected) following these rules:
- It will send all changed files to the device.
- If the file is in the
FULL_RELOAD_FILES
list, the app will completely restart on both the computer and the device. - If the file is in
WATCHED_FILES
or inside any folder inWATCHED_FOLDERS_RECURSIVELY
orWATCHED_FOLDERS
, the app will hot reload.
- If the file is in the
FULL_RELOAD_FILES
list, the app will completely restart on your computer. - If the file is in
WATCHED_FILES
or inside any folder inWATCHED_FOLDERS_RECURSIVELY
orWATCHED_FOLDERS
, the app will hot reload.