or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

discord-rpc-client.mdexceptions.mdindex.mdrich-presence.md
tile.json

tessl/pypi-pypresence

Discord RPC client written in Python for integrating applications with Discord's Rich Presence system

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pypresence@4.3.x

To install, run

npx @tessl/cli install tessl/pypi-pypresence@4.3.0

index.mddocs/

pypresence

A comprehensive Discord RPC client library for Python that enables applications to integrate with Discord's Rich Presence system. Pypresence provides both synchronous and asynchronous implementations for displaying rich status information including activity names, details, timestamps, and custom images in users' Discord profiles.

Package Information

  • Package Name: pypresence
  • Language: Python
  • Installation: pip install pypresence
  • Python Requirements: Python 3.8+
  • Cross-platform: Windows, Linux, macOS

Core Imports

import pypresence

Common imports for specific functionality:

from pypresence import Presence, AioPresence
from pypresence import Client, AioClient
from pypresence import PyPresenceException, DiscordNotFound

Basic Usage

Simple Rich Presence

from pypresence import Presence
import time

# Connect to Discord
RPC = Presence("your_client_id_here")
RPC.connect()

# Update presence
RPC.update(state="Playing Solo", details="In Main Menu")

# Keep alive
while True:
    time.sleep(15)

Async Rich Presence

import asyncio
from pypresence import AioPresence

async def main():
    RPC = AioPresence("your_client_id_here")
    await RPC.connect()
    
    await RPC.update(
        state="In Game",
        details="Level 5 - Forest",
        large_image="game_logo",
        large_text="My Amazing Game",
        start=int(time.time())
    )
    
    # Keep alive
    while True:
        await asyncio.sleep(15)

asyncio.run(main())

Architecture

Pypresence provides a layered architecture:

  • Presence/AioPresence: Simplified clients focused on Rich Presence activities
  • Client/AioClient: Full-featured RPC clients with Discord API access
  • BaseClient: Core IPC communication and connection management
  • Payload: Structured message builders for Discord RPC protocol
  • Exception Hierarchy: Comprehensive error handling for all Discord integration scenarios

The library handles cross-platform IPC communication automatically, discovering Discord's pipe/socket connections on Windows, Linux, and macOS.

Capabilities

Rich Presence Management

Simple interface for updating Discord Rich Presence with activity information, timestamps, images, and party details.

class Presence(BaseClient):
    def __init__(self, client_id: str, **kwargs): ...
    def connect(self): ...
    def update(self, pid: int = None, state: str = None, details: str = None,
               start: int = None, end: int = None,
               large_image: str = None, large_text: str = None,
               small_image: str = None, small_text: str = None,
               party_id: str = None, party_size: list = None,
               join: str = None, spectate: str = None,
               match: str = None, buttons: list = None,
               instance: bool = True, payload_override: dict = None): ...
    def clear(self, pid: int = None): ...
    def close(self): ...
class AioPresence(BaseClient):
    def __init__(self, client_id: str, **kwargs): ...
    async def connect(self): ...
    async def update(self, pid: int = None, state: str = None, details: str = None,
                     start: int = None, end: int = None,
                     large_image: str = None, large_text: str = None,
                     small_image: str = None, small_text: str = None,
                     party_id: str = None, party_size: list = None,
                     join: str = None, spectate: str = None,
                     match: str = None, buttons: list = None,
                     instance: bool = True): ...
    async def clear(self, pid: int = None): ...
    def close(self): ...

Rich Presence

Discord RPC Client

Full Discord RPC client with support for authentication, guild/channel operations, voice settings, and event subscriptions.

class Client(BaseClient):
    def __init__(self, client_id: str, **kwargs): ...
    def start(self): ...
    def authorize(self, client_id: str, scopes: list): ...
    def authenticate(self, token: str): ...
    def set_activity(self, pid: int = None, state: str = None, details: str = None, **kwargs): ...
    def get_guilds(self): ...
    def get_voice_settings(self): ...
    def register_event(self, event: str, func: callable, args: dict = None): ...
    def close(self): ...
class AioClient(BaseClient):
    def __init__(self, client_id: str, **kwargs): ...
    async def start(self): ...
    async def authorize(self, client_id: str, scopes: list): ...
    async def authenticate(self, token: str): ...
    async def set_activity(self, pid: int = None, state: str = None, details: str = None, **kwargs): ...
    async def get_guilds(self): ...
    async def get_voice_settings(self): ...
    async def register_event(self, event: str, func: callable, args: dict = None): ...
    def close(self): ...

Discord RPC Client

Exception Handling

Comprehensive exception hierarchy for handling Discord integration errors.

class PyPresenceException(Exception):
    def __init__(self, message: str = None): ...

class DiscordNotFound(PyPresenceException): ...
class InvalidPipe(PyPresenceException): ...
class InvalidArgument(PyPresenceException): ...
class ServerError(PyPresenceException): ...
class DiscordError(PyPresenceException): ...
class InvalidID(DiscordError): ...
class PipeClosed(PyPresenceException): ...
class ResponseTimeout(PyPresenceException): ...
class ConnectionTimeout(PyPresenceException): ...

Exception Handling

Types

class BaseClient:
    """Base client for Discord RPC communication"""
    def __init__(self, client_id: str, loop=None, handler=None, 
                 pipe=None, isasync: bool = False,
                 connection_timeout: int = 30, response_timeout: int = 10): ...
    
    def update_event_loop(self, loop): ...
    async def read_output(self): ...
    def send_data(self, op: int, payload): ...
    async def handshake(self): ...
class Payload:
    """Discord RPC payload builder"""
    def __init__(self, data: dict, clear_none: bool = True): ...
    
    @staticmethod
    def time() -> float: ...
    
    @classmethod
    def set_activity(cls, pid: int = None, state: str = None, 
                     details: str = None, **kwargs) -> 'Payload': ...