https://github.com/gnoviawan/fast-api-electron-js
Python Cross Platform APP using Electron JS and Fast API
https://github.com/gnoviawan/fast-api-electron-js
electronjs fastapi python
Last synced: 4 months ago
JSON representation
Python Cross Platform APP using Electron JS and Fast API
- Host: GitHub
- URL: https://github.com/gnoviawan/fast-api-electron-js
- Owner: gnoviawan
- License: mit
- Created: 2021-06-17T04:02:05.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-19T06:17:14.000Z (about 5 years ago)
- Last Synced: 2024-01-07T22:57:31.161Z (over 2 years ago)
- Topics: electronjs, fastapi, python
- Language: HTML
- Homepage:
- Size: 5.37 MB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Electron JS x Python Fast API
> Modern web UI x Python FAST API
## Preview

## Prerequisite
- Working Python environment (virtual environment is recommended), Python 3
- Know how to use Node.js command
## Features
1. Python Backend - do as you wish with python, do AI / ML / etc and send those data to modern web UI
2. Cross Platform APP using web UI
## Installing / Getting started
clone this git
```shell
git clone https://github.com/gnoviawan/fast-api-electron-js.git
```
## Initial Configuration
change directory to cloned git
```shell
cd fast-api-electron-js
```
install all python dependencies
```shell
npm run py-install
```
install all node js dependencies
```shell
npm install
```
## Developing
#### Directory Structure :
`engine/` : a python directory for Fast API, create/modify all python module there, keep the `api.py` file name if you want to easily building the app later.
`public/`: all frontend related files
`public/assets/js/python.js`: is responsible to communicate between our frontend and backend.
`public/assets/js/main.js`: electron main window
#### Preview your Application :
run this command to preview your app
```shell
npm run electron-dev
```
## Deploying / Publishing
#### Building Python :
before we building our app we have to build our Python FastAPI to .exe file ( windows ) or other executable format for each OS using PyInstaller and then call our Python Fast api as a child process inside electron js.
run this command to build python using `PyInstaller` library
please adjust the `api.spec` if you want to modify the build process or icon, please refer to the [PyInstaller documentation](https://pyinstaller.readthedocs.io/en/stable/spec-files.html)
```shell
npm run py-build
```
also if you are not using Windows change this code inside `public/assets/js/main.js` to another OS executable format ( not tested )
```javascript
const API_PROD_PATH = path.join(process.resourcesPath, "../lib/api/api.exe")
```
#### Build the application :
after we build our fast API it's time to build our main APP, run this command to build it
```shell
npm run electron-build
```
our app are published to this path `dist`
if you want to change the build options modify this config file `electron-builder.config.json` more about the options please check [electron-builder](https://www.electron.build/) documentation
## All Reference Links for this project
#### Server / Backend API ( Python )
[Python Fast API](https://fastapi.tiangolo.com/) = main package that create our API backend
[uvicorn](https://www.uvicorn.org/) = ASGI Python Server
#### Middleware (Javascript)
[Axios JS](https://axios-http.com/docs/intro) = package to communicate beetwen Python and Frontend
#### Frontend ( HTML, CSS, Javascript )
[Electron JS](https://www.electronjs.org/) = to create standalone application
[Tabler](https://tabler.io/) = Front end UI Kit / Framework
#### Utility
[Electron Builder](https://www.electron.build/) = packate to build our Electron APP
[Electron Reloader](https://www.npmjs.com/package/electron-reloader) = to automatic reload our Electron APP when in development stage
[Python Shell](https://github.com/extrabacon/python-shell) = to create Python shell inside Node.js Application, usefull when we in development stage
[PyInstaller](https://pyinstaller.readthedocs.io/en/stable/index.html) = build our python to executable format
## [Licensing](https://github.com/gnoviawan/fast-api-electron-js/blob/main/LICENSE.md)