Skip to main content

Tetry

PyPi version Code size

A simple python library for interacting with the TETR.IO API.

contents

About

This library is a simple wrapper around the TETR.IO API. It uses trio to provide a simple async interface.

Installation

installing from pip

python3 -m pip install tetry

installing from source

git clone https://github.com/apes0/tetry
cd tetry
python3 -m pip install -U .

Documentation

Coming soon!

Examples

Here you will find code examples for the library.

General api

from tetry import api

def printRecords(username):
    records = api.getRecords(username).records
    for name, record in records.items():
        print(f'{name}: {record}')

while (name := input()):
    printRecords(name)

Chat commands

from tetry import bot

bot = bot.Bot(token='token', commandPrefix='>')

@bot.chatCommand()
async def ping(_msg):
    ping = bot.getPing()
    await bot.room.send(f'The bot\'s ping is {round(ping*1000, 2)}ms')

bot.run()

Simple auto-host bot

import trio

from tetry.bot import Bot

bot = Bot(token='token')

@bot.event
async def ready():
    await bot.createRoom(False)

@bot.event
async def joinedRoom(room):
    print(room.invite)

@bot.event
async def userLeave(user):
    name = user['username']
    print(f'{name} has left')
    await bot.room.send(f'Goodbye {name}, hope to see you here again soon!')

async def start(room):
    delay = 20 # seconds
    needed = 2 # players
    if len(room.getPlaying()) >= needed:
        await room.send(f'Starting in {delay} seconds!')
        await trio.sleep(delay)
        if len(room.getPlaying()) >= needed:
            await room.startGame()
        else:
            await room.send('Not enough players!')
    else:
        await room.send('Not enough players!')

@bot.event
async def userJoin(user):
    room = bot.room
    name = user['username']
    await room.send(f'Welcome to this room, {name}!')
    await start(room)

@bot.event
async def gameEnd():
    room = bot.room
    print('the game has ended')
    await start(room)

bot.run()

Contribution

You can feel free to contribute to the this project by making a PR, making suggestions and opening issues for bugs/questions.

Notice

This library is NOT affiliated with, endorsed by, or otherwise associated with TETR.IO or osk.

Metadata

Release files for tetry 1.3.2

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

Built distribution (wheel)

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

Release files / tetry-1.3.2-py3-none-any.whl

Download URL tetry-1.3.2-py3-none-any.whl
Size 45.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cd620b26257f6f326076b67b319a42a91b3d1f0c39a5f8ab3bfcfdb559f25d8
BLAKE2b-256 checksum
How to use checksums
b8f0962746b48fe25721595c30557ed6d22af8a131b2c2f7901505afe5dd9e04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/57.4.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

Security for tetry 1.3.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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