Skip to main content

A tool to bridge local CLI applications with a remote Telegram interface.

Project description

Gramit: The Ultimate Telegram-to-Terminal Connector

Run Tests License: MIT Python 3.12+

Gramit is the most beautiful, robust, and secure way to bridge your local CLI applications with a remote Telegram interface. It allows you to run any command on your machine—from simple scripts to complex TUIs—and interact with it from anywhere in the world.

[!CAUTION] SECURITY WARNING: REMOTE ACCESS RISK

Gramit provides a bridge between your local machine and a remote Telegram interface. This allows remote command execution.

If you run a shell (like /bin/bash or cmd.exe) or any interactive tool through Gramit, anyone with access to your Telegram bot (and whose Chat ID is authorized) has full control over your machine.

USE ONLY IF YOU ARE HIGHLY SECURITY-AWARE.

  • Never share your GRAMIT_TELEGRAM_TOKEN.
  • Ensure your GRAMIT_CHAT_ID is correctly configured to your ID only.
  • Be extremely cautious when bridging shells or administrative tools.

🌟 Key Features

🚀 Dual Output Modes

Gramit offers two powerful ways to bridge your terminal output to Telegram:

  1. Standard Mode (IO): Directly captures the stdout of your process via a Pseudo-Terminal (PTY). Perfect for line-based apps and scripts. Gramit intelligently aggregates and debounces output to ensure you don't get spammed with dozens of tiny messages.
  2. External Stream Mode (-o / --output-stream): For complex TUI applications where raw terminal output is "noisy" (filled with borders, colors, and ANSI codes), you can instruct Gramit to "tail" a clean side-log file instead.

🖥️ Native Terminal Experience

Gramit isn't just a blind pipe; it respects your terminal:

  • Terminal Size Inheritance: Child processes automatically inherit the size of your host terminal on startup.
  • Dynamic Resizing: Resize your local terminal window, and Gramit propagates the change to the child process instantly (SIGWINCH support).
  • Local Mirroring: See the TUI running locally in your terminal while you interact with it remotely via Telegram.
  • Robust Cleanup: When you exit, Gramit performs a full terminal restoration—clearing the screen, homing the cursor, disabling mouse tracking, and exiting alternate screen buffers. No more "broken" terminals!

🔒 Built-in Security

  • Locked-down by Default: Only messages from your specific chat_id are processed.
  • Credential Safety: Tokens are handled via environment variables or secured .env files.
  • Rate Limiting: Protects your bot and machine from memory exhaustion and API flooding.

💡 Pro Use Case: Gemini CLI

Interactive AI CLIs are the perfect companions for Gramit. Here is how to set up Gemini CLI for an optimal remote experience:

  1. Instruct the AI: Add a rule to your GEMINI.md or system prompt: "Log all final responses into a file named gemini.log".
  2. Launch with Gramit:
    gramit -o gemini.log gemini
    
  3. The Result: You see the full, beautiful TUI locally if you are at your desk. When you're away, you send prompts via Telegram, and Gramit tails the clean gemini.log to send the AI's responses back to you.

🛠️ Setup

  1. Installation

    Install Gramit using your favorite Python package manager:

    Using pipx (Recommended for CLI tools):

    pipx install gramit
    

    Using uv:

    # Run without installing
    uvx gramit --help
    
    # Or install as a tool
    uv tool install gramit
    
  2. Get a Telegram Bot Token

    • Talk to the @BotFather on Telegram.
    • Create a new bot and copy the token.
  3. Set Environment Variables

    • Create a file named .env in your project root or your home directory.
    • Add your credentials (and secure the file: chmod 600 .env):
      GRAMIT_TELEGRAM_TOKEN="8559400368:AAEECcgfbQMC19bvNxW3YsdEdrnGNQeqZbY"
      GRAMIT_CHAT_ID="YOUR_CHAT_ID"
      
  4. Find Your Chat ID If you don't know your ID, run:

    gramit --register
    

    Send any message to your bot, and it will reply with your ID.


📖 Usage Examples

Simple Command:

gramit ping 8.8.8.8

Interactive TUI with Side-Log:

# Start our built-in example chat app
gramit -o tui_echo.log python examples/tui_echo_with_log.py

🐧 Platform Support & Contributions

Gramit is currently only tested on Linux (bash).

Because it relies on native PTY features (os.forkpty, termios, fcntl), behavior on macOS or Windows (WSL) may vary.

Contributions are highly welcomed! If you've tested Gramit on other OSes or terminals and found bugs (or fixes), please open an issue or a PR.

📜 License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gramit-0.3.1.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gramit-0.3.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file gramit-0.3.1.tar.gz.

File metadata

  • Download URL: gramit-0.3.1.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gramit-0.3.1.tar.gz
Algorithm Hash digest
SHA256 730897e8ca4ef707192b3e19a8cd04b3f7e95a75175d7293c3f41dddf6b3cae2
MD5 d4547f3c0ee11f429668b9aec3c53c5b
BLAKE2b-256 c20039ceb04e035f04e3ee60da0bb164afc15a132f42bd3ee4a19e8cb26b14fd

See more details on using hashes here.

File details

Details for the file gramit-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: gramit-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gramit-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed1466350099e23af6116a8464f3164e8e633a1b2aa76769289f2a9938d5470c
MD5 3753eb281c2b1d79c6a2833a883d06fe
BLAKE2b-256 deeaec1086c3718d56c72f2b41fc855d87ecd520b87288f154c1d1cdcbff9e04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page