Coder Social home page Coder Social logo

dieharders / example-tauri-python-server-sidecar Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 1.0 157 KB

An example desktop app built using the Tauri framework to bundle Next.js with a Python server.

CSS 4.22% TypeScript 56.21% JavaScript 8.19% Rust 11.83% Python 19.56%
fastapi nextjs python tauri-app native-apps desktop-app

example-tauri-python-server-sidecar's Introduction

Example Tauri App using a Python server

A native web-app using the Tauri framework that spawns a subprocess for a backend server (FastAPI).


Introduction

This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend.

It is intended to show how to build hybrid language apps that work locally on a client's computer.

We do this to package up dependencies to make installation easier on the user and to allow the front-end access to the OS's disk, camera, and other native hardware features.

We make use of PyInstaller to compile binaries of all our code so that the user doesn't have to worry about installing dependencies. Tauri accomplishes this interoperability with what it calls "sidecars" which you can use to "load" in some arbitrary runtime. This is defined in the tauri.conf.json file. See here for more info.

Unfortunately this is done through Rust which some (including myself) are not familiar. Therefore, after many a visit to StackOverflow I created this example project in case others or myself ever need to jump-start a new native app.


How It Works

  • Tauri takes your front-end UI written in javascript (or Next.js framework in this case) and creates a native webview to display it. This makes the file size much smaller.

  • In main.rs we spawn a main.py script which creates our api server on localhost:8008 and can be used to spawn any other binaries or python code you like.

  • Most importantly, when the user closes the GUI window, all processes and subprocesses are shutdown properly.

  • 3rd party client apps could use this api to perform any functions needed. Use it to run ai inference, offload intensive tasks, manually kick-off or orchestrate processes.


Getting Started

Dependencies

First, install the dependencies for javascript:

pnpm install

Install dependencies for python listed in your requirements.txt file:

Be sure to run this command with admin privileges. This command is optional and is also run on each pnpm dev.

pip install -r requirements.txt

Run

Then, run the app in development mode:

pnpm tauri dev

Build

In case you dont have PyInstaller installed:

pip install -U pyinstaller

A note on compiling Python exe (the -F flag bundles everything into one .exe). You won't need to run this manually each build, I have included it in the build scripts.

  • pyinstaller -c -F your_program.py

Build app for production:

pnpm tauri build

This creates an installer located here:

  • <project-dir>\src-tauri\target\release\bundle\nsis

Learn More

example-tauri-python-server-sidecar's People

Contributors

dieharders avatar

Stargazers

Justin Garza avatar 陈磊 avatar yanghongbo avatar Diogo André Silvares Dias avatar Zhiyuan Ning avatar Yeow Zi Qin avatar Issac Liu avatar Ari Bermeki avatar  avatar Brad Pillow avatar Seonu Jang avatar Minki Kim avatar Jonathan Sundqvist avatar  avatar Seth Goldin avatar  avatar

Watchers

 avatar  avatar

Forkers

alitrack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.