A simple file based bridge between Python and browser JavaScript
Project description
ItWorks
A ridiculously simple Python + Browser bridge using plain text files.
itworks lets Python and JavaScript communicate without any complex:
- servers
- sockets
- APIs
- Flask
- WebSockets
- dependencies
It's perfect for:
- local dashboards
- automation tools
- browser + Python projects
- rapid and easy prototyping
- offline applications
- beginners who find Flask complicated
- people who find flask and javascript hard (Like me:))
How It Works
Communication uses 2 files only!
from_js.txt - Browser writes, Python reads to_js.txt - Python writes, Browser reads
The flow:
Browser -> from_js.txt -> Python Python -> to_js.txt -> Browser
Python clears incoming messages after reading them to avoid complicated issues.
Functions:
itworks.throw(filepath, data)
Write data from Python -> Browser.
Example:
import itworks
itworks.throw("to_js.txt", "Hello from Python")
itworks.catch(filepath)
Read data from Browser -> Python.
Automatically clears the file after reading.
Returns:
message string if data exists None if file is empty or missing
Example:
import itworks
msg = itworks.catch("from_js.txt")
if msg:
print(msg)
itworks.peek(filepath)
Read a file WITHOUT clearing it.
Useful for debugging.
Example:
print(itworks.peek("from_js.txt"))
itworks.lazy(from_js, to_js, output_html="index.html", poll_interval=500)
Automatically generates a full browser UI.
Includes:
input box output panel send button folder picker auto polling connection tester
Example:
import itworks
itworks.lazy(
from_js="from_js.txt",
to_js="to_js.txt"
)
This creates:
index.html
Open it in Chrome for it to work
itworks.engine(from_js, to_js, poll_interval=500)
Generates a minimal JavaScript engine for custom UIs.
Example:
import itworks
js = itworks.engine(
from_js="from_js.txt",
to_js="to_js.txt"
)
with open("engine.html", "w") as f:
f.write(js)
Full Example
import time
import itworks
while True:
msg = itworks.catch("from_js.txt")
if msg:
print("Browser:", msg)
response = f"Python received: {msg}"
itworks.throw("to_js.txt", response)
time.sleep(0.5)
Browser UI generator:
import itworks
itworks.lazy("from_js.txt", "to_js.txt")
Open the generated HTML in chrome file.
Browser Requirements
ONLY Works in:
Chrome Edge Chromium browsers
Does NOT fully work in Firefox.
Error Handling
throw() raises OSError for:
missing directories permission problems unexpected write errors
catch() safely returns None on most failures.
Minimal Echo Example
import time
import itworks
while True:
msg = itworks.catch("from_js.txt")
if msg:
itworks.throw("to_js.txt", f"Echo: {msg}")
time.sleep(0.5)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file itworks-1.0.0.tar.gz.
File metadata
- Download URL: itworks-1.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc6674707762d3699af66589a221fd0af11d9fb2837dfe8c8ebe9c1dc5cc3991
|
|
| MD5 |
e9a3af46c2a0e44c911a937c77986593
|
|
| BLAKE2b-256 |
d63d5f7c21a2abc96fcb616202535fa205d9821d1af7ca855e6bd475c16f875c
|
File details
Details for the file itworks-1.0.0-py3-none-any.whl.
File metadata
- Download URL: itworks-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4b34ab5145f4b8c72bf8ed92763f06cb638ea6f2cfa29a519c50cbcfa4e6d69
|
|
| MD5 |
9f9498622cf6b0339611309451d2156c
|
|
| BLAKE2b-256 |
dc61f98d1eb73d3aefe3b64d97be1675d8fc15552361780a175ede182baa8c8a
|