Skip to main content

A simple framework for building robust social media bots for multiple networks

Project description

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.

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

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

polybot-0.9.6.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

polybot-0.9.6-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file polybot-0.9.6.tar.gz.

File metadata

  • Download URL: polybot-0.9.6.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polybot-0.9.6.tar.gz
Algorithm Hash digest
SHA256 5e6d0e15194472cbca1a4285905336320995162bfb07fae594352d3c23eef458
MD5 f85a222f0df73847037e1eb87b93b690
BLAKE2b-256 93a415035bae0c865b2386b05d82fa920bd338e664f5c8446d24a52819e622b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for polybot-0.9.6.tar.gz:

Publisher: publish.yml on russss/polybot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polybot-0.9.6-py3-none-any.whl.

File metadata

  • Download URL: polybot-0.9.6-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polybot-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 21ee3d90720b30c4c5578f418a00702c62cf5c25efe9e684d7de6c7d572f44f8
MD5 7fb25f7297a578210700b753634f5691
BLAKE2b-256 8fe9387e35ecfb2a3ae2a41747c30d4557c9cf53ed062cb5ba15af519a1eaf9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for polybot-0.9.6-py3-none-any.whl:

Publisher: publish.yml on russss/polybot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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