Skip to main content

Intro

A client for Pokemon Showdown! for Python 3.4 and 3.5. This was written to make it easier to write bots, interact with users, moderate chat rooms, and collect data.

Setup

Install the package with pip3 install --user showdownpy. This will also install the package's websockets and aiohttp dependencies if you do not already have them.

Example

Examples have been provided in the ./examples directory. Make sure to create your own versions of the login.txt and owner.txt files in ./examples/data/ directory. Templates for those files have been provided.

The client on its own doesn't do very much, and is instead intended to be extended and modified. This can be done through various "hook" coroutines left in the base class. The following program uses the on_private_message hook to echo back the content of any PMs it receives.

"""
An example client that echoes back any message that is 
private messaged to it
"""
import showdown

with open('./examples/data/login.txt', 'rt') as f:
    username, password = f.read().strip().splitlines()

class EchoClient(showdown.Client):
    async def on_private_message(self, pm):
        if pm.recipient == self:
            await pm.reply(pm.content)

EchoClient(name=username, password=password).start()

Other hooks include on_connect, on_login, on_room_init, on_room_deinit, on_query_response and on_chat_message.

These hooks are by no means all inclusive (Showdown has somewhere upwards of 40 different types of messages it uses to interact with clients in its protocol), and so a catch-all hook on_receive is also present. Each hook call is given its own task on the event loop, so you can have multiple active coroutines spawned from the same hook.

The bot can also be used for collecting data on battles. The following bot anonymously joins ongoing matches in the format 'OU' and saves replays of them when a user finishes.

"""
An example client that joins all OU battles
and saves replays.
"""
import showdown

with open('./examples/data/login.txt', 'rt') as f:
    username, password = f.read().strip().splitlines()

class ReplayClient(showdown.Client):
    async def on_query_response(self, response_type, data):
        if response_type == 'roomlist':
            for battle_id in set(data['rooms']) - set(self.rooms):
                await self.join(battle_id)

    async def on_receive(self, room_id, inp_type, params):
        if inp_type == 'win':
            with open('./data/' + room_id, 'wt') as f:
                f.write('\n'.join(self.rooms[room_id].logs))

    @showdown.Client.on_interval(interval=3)
    async def check_ou(self): 
        await self.query_battles(tier='gen7ou', lifespan=3)

ReplayClient(name=username, password=password).start(autologin=False)

It is recommended that you save local copies of these matches rather than upload them, as to not overwhelm Showdown's replay server.

Contributions

This package is still a work in progress, and any contributions would be great! I'm currently prioritizing documentation over new features, but if you have an idea for something let me know. Feel free to share anything you make with the client and if its succint enough I may add it to the pool of examples.

Release files for showdownpy 0.1.5

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

Source distribution (sdist)

Source distribution for showdownpy 0.1.5
File Size Uploaded
showdownpy-0.1.5.tar.gz 24.1 kB Details

Built distribution (wheel)

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

Total release size: 51.1 kB

Release files / showdownpy-0.1.5.tar.gz

Download URL showdownpy-0.1.5.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
68de90dc98b4730ea24d4d0582a49caabc1d042afba73259fb1bd77a5ebff6ed
BLAKE2b-256 checksum
How to use checksums
cf2c3c94b3fc5c67463c269b1499b2b655299e910a7143dbf17a53799ae16455
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.1

Release files / showdownpy-0.1.5-py3-none-any.whl

Download URL showdownpy-0.1.5-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21f73779a1b73f43bb9ad5120331ba3272e8a722b715269e8079a6c007f6c268
BLAKE2b-256 checksum
How to use checksums
0f51d40ab0cd3f724f85139ade1d8c5c43921d981f63bd7b20905e6434ad8b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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