Metadata-Version: 2.4
Name: itworksbetter
Version: 1.0.0
Summary: Seven functions. Clean and easy. Infinite possibilities.
Author-email: "Atheer B. Muzzammil" <teamleadertrue@gmail.com>
License: MIT
Project-URL: Github, https://github.com/Ahmad170412/itworksbetter
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: User Interfaces
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# itworksbetter

> Seven functions. One loop. Infinite possibilities.

`itworksbetter` is a tiny Python library that creates a live communication bridge between Python and your browser.

No frameworks.
No WebSockets.
No async confusion.
No frontend setup.

Just:

```python
msg = iwb.catch()
iwb.throw("hello")
```

That’s it.

---

# Why itworksbetter?

Most browser ↔ Python communication tools are heavy.

You usually need:

* Flask
* FastAPI
* SocketIO
* React/Vue
* Routes
* APIs
* async/await
* frontend tooling

`itworksbetter` strips all of that away.

You write a single Python loop.

The browser becomes your UI instantly.

Perfect for:

* AI tools
* Browser dashboards
* Python assistants
* Internal tools
* Local automation
* Rapid prototypes
* Teaching
* Experiments
* Live terminals
* Custom browser interfaces

---

# Installation

```bash
pip install itworksbetter
```

---

# The Philosophy

Seven functions.

One loop.

Infinite possibilities.

```python
while True:
    if msg := iwb.catch():
        iwb.throw(f"You said: {msg['text']}")
```

That loop *is* your backend.

---

# Quick Start

## 10-Line Echo Bot

```python
import time
import itworksbetter as iwb

iwb.lazy(title="Echo Bot", theme="dark")
iwb.init()

while True:
    if msg := iwb.catch():
        iwb.throw(f"You said: {msg.get('text', '')}")

    time.sleep(0.01)
```

Run it:

```bash
python app.py
```

Your browser opens automatically.

Type messages into the UI.

Python receives them instantly.

---

# How It Works

`itworksbetter` runs a lightweight local HTTP server.

The browser:

* sends messages to Python
* polls for responses
* displays live output

Internally it uses:

* queues
* threads
* HTTP
* JSON

No external services required.

Everything stays local.

---

# The Seven Functions

---

# 1. `lazy()`

Configure the browser UI before launch.

```python
iwb.lazy(title="My App", theme="light")
```

## Parameters

| Parameter | Type  | Default           |
| --------- | ----- | ----------------- |
| `title`   | `str` | `"itworksbetter"` |
| `theme`   | `str` | `"dark"`          |

## Themes

Supported:

* `"dark"`
* `"light"`

---

# 2. `init()`

Start the local server and connect to your browser.

```python
iwb.init()
```

## Example

```python
iwb.init(port=8080)
```

## Parameters

| Parameter       | Type   | Default |
| --------------- | ------ | ------- |
| `port`          | `int`  | `8000`  |
| `open`          | `bool` | `True`  |
| `auto_fallback` | `bool` | `True`  |

## Features

* Automatically opens your browser
* Auto-finds an open port if needed
* Runs the server in a background thread
* Cleans itself up on exit

## Example Output

```text
✅ Using port: 8000
🚀 itworksbetter v1.0.0 running at http://localhost:8000
📡 Echo Bot | Theme: dark
💡 Waiting for messages...
```

---

# 3. `catch()`

Receive messages from the browser.

```python
msg = iwb.catch()
```

## Returns

### Message received

```python
{"text": "hello"}
```

### No message waiting

```python
None
```

## Typical Usage

```python
if msg := iwb.catch():
    print(msg["text"])
```

---

# 4. `throw()`

Send data to the browser.

```python
iwb.throw("hello")
```

## Supports

Any JSON-serializable data:

```python
iwb.throw("text")

iwb.throw({
    "user": "alex",
    "online": True
})

iwb.throw([1, 2, 3])

iwb.throw(123)
```

The browser UI automatically formats and displays the output.

---

# 5. `close()`

Shutdown the server cleanly.

```python
iwb.close()
```

## What it does

* Stops browser polling
* Shuts down the HTTP server
* Frees the port immediately
* Clears message queues

Useful if you want to restart the server without restarting Python.

---

# 6. `help()`

Show a built-in mini guide.

```python
iwb.help()
```

Displays:

* all functions
* examples
* quick usage tips

Great for learning the API quickly.

---

# 7. `engine()`

Get the JavaScript browser engine.

```python
js = iwb.engine()
```

This lets you build completely custom browser UIs while still using the same Python communication system.

---

# Custom UI Example

## Python

```python
import itworksbetter as iwb
import time

iwb.init()

while True:
    if msg := iwb.catch():
        iwb.throw({
            "reply": msg["text"].upper()
        })

    time.sleep(0.01)
```

---

## HTML

```html
<!DOCTYPE html>
<html>
<body>

<input id="msg">
<button id="send">Send</button>

<pre id="output"></pre>

<script>
/* paste iwb.engine() output here */
</script>

<script>
const input = document.getElementById("msg");
const output = document.getElementById("output");

document.getElementById("send").onclick = () => {
    itworksbetter.send(input.value);
};

itworksbetter.listen((data) => {
    output.textContent += JSON.stringify(data) + "\n";
});
</script>

</body>
</html>
```

---

# Architecture

The library uses two internal queues:

| Queue       | Direction        |
| ----------- | ---------------- |
| `_incoming` | Browser → Python |
| `_outgoing` | Python → Browser |

Communication flow:

```text
Browser → /send → Python queue
Python → /recv → Browser poll
```

Polling interval:

* `50ms` by default

---

# Design Goals

`itworksbetter` was built to be:

* Minimal
* Easy to learn
* Beginner-friendly
* Fast to prototype with
* Pure Python
* Easy to debug
* Easy to customize

Not a replacement for full production frameworks.

Instead, it focuses on:

* simplicity
* immediacy
* experimentation
* local tools
* rapid development

---

# Example Projects

You can build:

* AI chat interfaces
* Browser terminals
* Live dashboards
* Python control panels
* Automation UIs
* Teaching demos
* Monitoring tools
* Local admin panels
* Game prototypes
* Browser-based utilities

---

# Complete Example

```python
import time
import itworksbetter as iwb

iwb.lazy(
    title="Assistant",
    theme="dark"
)

iwb.init(port=8000)

while True:

    if msg := iwb.catch():

        text = msg.get("text", "")

        if text == "ping":
            iwb.throw({"response": "pong"})

        elif text == "time":
            iwb.throw({
                "time": time.time()
            })

        else:
            iwb.throw({
                "echo": text
            })

    time.sleep(0.01)
```

---

# Notes

* Everything runs locally
* Uses standard HTTP
* No WebSockets required
* No external dependencies
* Works with any frontend framework
* Browser communication is JSON-based

---

# Version

Current version:

```python
1.0.0
```

---

# License:

Copyright (c) 2026 Atheer B. Muzzammil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.




## Most tools make browser communication feel harder than it needs to be.

`itworksbetter` reduces it down to:

* `catch()`
* `throw()`
* one loop

#### And surprisingly, that’s enough for a lot of powerful ideas.
#### Go build today with `itworksbetter!` 
