balelink
Log in to Bale with your own account, then send and receive messages from Python, the command line, or plain HTTP.
Getting started · Guide · HTTP gateway · FAQ · فارسی
import asyncio
from balelink import BaleClient, filters as F
bale = BaleClient("me")
@bale.on_message(F.private & F.command("ping"))
async def ping(msg):
await msg.reply("pong")
async def main():
async with bale: # reuses the saved login
await bale.send_text("09121234567", "hello") # by phone number
await bale.run_forever()
asyncio.run(main())
Features
| Area | What you get |
|---|---|
| Messages | text, photos, voice, video, audio, files, locations; reply, edit, delete, forward, pin, react, typing, seen |
| Receiving | handlers with composable filters, async for streams, wait_for; new, edited and deleted messages; connection events |
| Chats | history (paged through the whole chat), recent chats, clear and delete |
| Contacts | check a number, add, rename, block and unblock, user info |
| Groups | create, edit, members, admins, invite links, join, leave |
| Login | phone and code, optional two-step password, saved and reused |
| Gateway | an HTTP service in the style of WAHA: sessions, webhooks with event filters and signatures, send by URL, media download |
| Tooling | CLI (balelink login / send / listen / serve), FakeTransport for testing bots offline, stable error codes |
Install
pip install balelink # library and CLI
pip install "balelink[gateway]" # plus the HTTP gateway
Python 3.9 or newer. Built on aiobale (MIT), which does the protocol work. See NOTICE.
Log in
balelink login me
It asks for your phone number, Bale sends a code, you type it (and your two-step password, if you set one). The login is saved to ~/.balelink/me.bale and later runs need no code.
From code:
await bale.login("09121234567",
code=lambda: input("code: "),
password=lambda: input("two-step password: ")) # only asked if needed
Numbers can be written 0912..., +98 912... or in Persian digits.
Receive
@bale.on_message(F.private & F.text) # filters combine with & | ~
@bale.on_message(F.group & F.text_contains("help"))
@bale.on_message(F.command("start", "help"))
@bale.on_message(F.photo) # also F.voice, F.video, F.location, ...
@bale.on_edited(F.private)
Handlers can be async or plain functions; one that raises does not stop the others. Your own messages are not delivered unless you pass deliver_own=True.
async for msg in bale.messages(F.private): # a stream
...
reply = await bale.wait_for(F.from_user(42), timeout=60)
Send
await bale.send_text("09121234567", "hi") # phone number, chat id, User or Message
await msg.reply("quoted reply")
await bale.send_photo(chat, "pic.jpg", caption="look")
await bale.send_file(chat, "note.ogg", kind=FileKind.VOICE)
await bale.send_location(chat, 35.7, 51.4)
await sent.edit("new text"); await sent.react("👍"); await sent.delete()
async with bale.typing(msg): # shows "typing..." while you work
...
async for m in bale.iter_history(chat): ... # the whole chat, newest first
Text over 4000 characters is split for you, and sends keep a small gap (min_send_interval) so a burst does not look like a script.
Command line
balelink login me
balelink send me 09121234567 "hello"
balelink listen me
balelink serve # the HTTP gateway
HTTP gateway
BALELINK_API_KEY=change-me balelink serve # http://127.0.0.1:8787
Sessions, login, sending, contacts, groups, and webhooks for incoming events, all over HTTP. Interactive docs are at /docs. See the gateway guide.
Testing your own bot
from balelink import BaleClient
from balelink.testing import FakeTransport
fake = FakeTransport(logged_in=True)
async with BaleClient("t", transport=fake) as bale:
...
await fake.deliver("/ping", chat_id=42)
assert fake.sent[-1].text == "pong"
Status
Alpha. Checked by hand on one live account:
| Works live | Not yet tried live |
|---|---|
| login with a code, reconnecting from the saved login | groups |
| sending and receiving text, photos, voice, locations | contact changes, blocking |
| downloading files, reading history | forwarding, pinning |
| contacts, block list and chat list (read-only) | edit/delete events, the HTTP gateway |
Everything is also covered by 150+ offline tests. Run examples/smoke_test.py on your own account and open an issue with the output if something fails.
How it is built
BaleClient talks to a small Transport protocol, and balelink/_aiobale.py is the only file that imports aiobale. When Bale or aiobale changes, that one file changes. A contract test checks it against the installed aiobale.
Limits
Private chats and groups only (no channels or calls). Formatted text, buttons and polls are not exposed yet. Bale throttles phone-number lookups, so balelink remembers every number it resolves (see the FAQ).
MIT licensed. Contributing · Changelog · Security
Metadata
Release files for balelink 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| balelink-0.1.0.tar.gz | 73.7 kB | With provenance | Details for balelink-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| balelink-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for balelink-0.1.0-py3-none-any.whl |
Total release size: 127.9 kB
Release files / balelink-0.1.0.tar.gz
| Download URL | balelink-0.1.0.tar.gz |
|---|---|
| Size | 73.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc5d7abc150ba2587cbbb077171654e9929690084b3f57193db5d6bcfce5fdac
|
|
BLAKE2b-256 checksum How to use checksums |
444693ef69c96ef27276bf14c8504640f1aeb5a374e118c52fa5dc2a188f1a51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / balelink-0.1.0-py3-none-any.whl
| Download URL | balelink-0.1.0-py3-none-any.whl |
|---|---|
| Size | 54.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33dcf6b4e5d59f5c49e06e0ff2cbd91e4c99af7da49b8ffb851398be41976485
|
|
BLAKE2b-256 checksum How to use checksums |
d173139adf5e9770755bb30ca211906fb530a6cc224d4e7cb975cd95cea25704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for balelink 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for balelink-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.