Metadata-Version: 2.4
Name: tablogger
Version: 0.1.7
Summary: Universal logging function for Python — tablog() works everywhere
License: MIT
Keywords: debug,devtools,fullstack,logging,tablog,unified
Requires-Python: >=3.8
Requires-Dist: websocket-client>=1.6
Provides-Extra: fastapi
Requires-Dist: starlette>=0.20; extra == 'fastapi'
Provides-Extra: flask
Requires-Dist: flask>=2.0; extra == 'flask'
Description-Content-Type: text/markdown

# tablogger

Python SDK for [tablogger](https://github.com/sejoonpark99/TabLog) — one function, every language, one terminal.

`tablog()` is a drop-in replacement for `print()` that routes your logs to a single unified terminal alongside your JS/Rust services. Run `npx tablogger` once and see everything in one place.

```
[React]    button clicked
[FastAPI]  GET /api/users 200 18ms
[Python]   processing 42 items       main.py:18
[Python]   done in 4ms               main.py:31
```

[![PyPI](https://img.shields.io/pypi/v/tablogger)](https://pypi.org/project/tablogger/)
[![license](https://img.shields.io/badge/license-MIT-blue)](#license)

---

## Installation

```bash
pip install tablogger
```

With framework extras:

```bash
pip install tablogger[fastapi]
pip install tablogger[flask]
```

---

## Quick start

**1. Start the terminal**

```bash
npx tablogger
```

**2. Log from Python**

```python
from tablog import tablog

tablog("server started")
tablog("query result:", {"rows": 42})
```

Logs appear instantly in the tablogger terminal with source label, file, and line number.

---

## API

### `tablog(*args)`

Drop-in replacement for `print()`. Accepts any number of arguments — strings are passed through, everything else is JSON-serialized.

```python
from tablog import tablog

tablog("user logged in")
tablog("query result:", {"rows": 42})
tablog("count:", 100)
```

### `init(source, port)`

Call once at startup to set a custom source label or port. Optional — auto-detects the running framework if not called.

```python
from tablog import init

init(source="payments-service", port=4242)
```

---

## Framework integrations

### FastAPI

```python
from tablog import tablog
from tablog.middleware import TablogMiddleware

app.add_middleware(TablogMiddleware, source="FastAPI")

@app.get("/api/users")
async def get_users():
    tablog("fetching users")
    return {"users": users}
```

### Flask

```python
from tablog.middleware import TablogFlaskMiddleware

TablogFlaskMiddleware(app)
```

### LangChain / LlamaIndex

```python
from tablog.langchain import TablogCallbackHandler

handler = TablogCallbackHandler(source="MyRAGApp")
chain = RetrievalQA.from_chain_type(llm=llm, callbacks=[handler])
```

---

## Log levels

```python
tablog("all good")                           # default
tablog("cache miss rate high", level="warn")  # yellow
tablog("payment failed", level="error")       # red
```

---

## Behaviour

- **Fire and forget** — `tablog()` returns immediately; sending is async in a background thread.
- **Auto-reconnect** — if the tablogger server isn't running yet, messages queue up and flush once it starts.
- **Fallback** — always echoes to stdout via `print()` even when the server is unreachable.
- **Auto-detection** — detects FastAPI, Flask, Django, and other frameworks automatically.

---

## Environment variables

| Variable | Default | Description |
|----------|---------|-------------|
| `TABLOG_PORT` | `4242` | Port of the tablogger server |
| `TABLOG_SOURCE` | auto-detected | Override source label |

---

## Other SDKs

| Language | Package |
|----------|---------|
| JavaScript / TypeScript | [npmjs.com/package/tablogger](https://www.npmjs.com/package/tablogger) |
| Rust | [crates.io/crates/tablogger](https://crates.io/crates/tablogger) |

---

## License

MIT
