Skip to main content

PyPI version

Polybot

Polybot is a simple framework for building robust social media bots for multiple networks in Python.

Features

  • Automatically post to X/Twitter, Mastodon, Bluesky.
  • A friendly command-line setup interface to handle the authentication hassle for you.
  • Automatic state persistence - just put your state in the self.state dict and it'll get saved/restored across runs.
  • Graceful handling of different post length limits and image upload sizes between services.

X/Twitter support is no longer regularly tested as the authors no longer use it. Reliability can't be guaranteed but pull requests are welcome.

Limitations/Wishlist

  • Polybot currently doesn't have support for receiving messages, so it's only useful for post-only bots.

Getting started

Install Polybot from PyPi using your package manager of choice.

from polybot import Bot

class HelloWorldBot(Bot):
  def main(self):
    while True:
      self.post("Hello World")
      sleep(300)

HelloWorldBot('helloworldbot').run()

To configure the accounts the bot uses, just run:

./helloworldbot.py --setup

You'll be guided through authenticating and a config file will be automatically created.

Use the --profile [name] to save and use a specific state/config.

By default, the bot will run in development mode, where it doesn't actually post to services. To run in live mode, pass the --live flag, or to run in interactive mode pass the --interactive flag.

Images

One or more images can be attached by creating an Image object, which can be created from a path, a file object, or bytes.

from polybot import Image

self.post("Hello World",
  images=[Image(path="/path/to/image", mime_type="image/png", description="Alt text")]
)

Images are automatically resized to below the maximum allowable size on each platform.

Handling post length limitations

Services have differing post length limits, so a list of messages can be passed to the post method, and Polybot will choose the longest message which is supported by each configured service.

self.post(["This is a short message", "This is a much longer message......"])

Alternatively, the wrap argument can be used to split a message into multiple posts:

self.post("Long message...", wrap=True)

State management

Polybot provides a dictionary at self.state where your bot can store any data which needs to be persisted, to avoid repeating posts.

The state dictionary is serialised to a file called <bot_name>.state in the local directory. This automatically happens when the process is terminated, but you can also trigger this by calling self.save_state(), or by sending the process a SIGHUP signal.

Bots which use Polybot

Release files for polybot 0.9.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polybot 0.9.7
File Size Uploaded
polybot-0.9.7.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polybot 0.9.7
File Interpreter ABI Platform
polybot-0.9.7-py3-none-any.whl Python 3 none any Details

Total release size: 25.2 kB

Release files / polybot-0.9.7.tar.gz

Download URL polybot-0.9.7.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b86fdd2a72b99eb63d6f081769f0b41d53b894a36d38de785a5a928d66a748b2
BLAKE2b-256 checksum
How to use checksums
518645797f6d83a8791284b35f9b0fbd72faf5d8ea4634c2dfc7bd2ff96857e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Sep 28, 2025.

Transparency log

Release files / polybot-0.9.7-py3-none-any.whl

Download URL polybot-0.9.7-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
736b3beacee6af7689e9a9095293bafd5a31d6c4ace7ec1b12a9614281801556
BLAKE2b-256 checksum
How to use checksums
881ca65d6e19dcad885c8a364715109acf0d65a5ad2fe07a66b6ae77529459c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Sep 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.7 This release

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page