Registry / communication / pypresence

pypresence

JSON →
library4.6.1pypypi✓ verified 87d ago

PyPresence is a Discord RPC client library for Python, enabling developers to integrate their applications with Discord's Rich Presence feature. It supports both synchronous and asynchronous operations for updating a user's status. The current version is 4.6.1, and it typically has releases for bug fixes and new Discord RPC features.

pip install pypresence
INSTALL
IMPORT
SIG · PYPRESENCE
P
pypresence
communicationpythonv4.6.1
Install
1.5s avg
Import
215ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.227s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.202s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Presence
from pypresence import Presence
For synchronous Discord Rich Presence updates.
AioPresence
from pypresence import AioPresence
For asynchronous Discord Rich Presence updates, typically used with asyncio.
InvalidID
from pypresence.exceptions import InvalidID
Exception raised when an invalid Discord Application ID is used.
PipeError
from pypresence.exceptions import PipeError
Exception raised when unable to connect to Discord IPC pipe.

This quickstart demonstrates how to use `pypresence.Presence` for synchronous Rich Presence updates. It connects to Discord, sets a custom presence with details, timestamps, images, and buttons, then maintains it for 30 seconds before disconnecting. Remember to replace `123456789012345678` with your actual Discord Application ID in production, or set the `PYPRESENCE_CLIENT_ID` environment variable.

import time import os from pypresence import Presence # Get CLIENT_ID from environment or set a placeholder # Replace with your actual Discord Application ID CLIENT_ID = os.environ.get('PYPRESENCE_CLIENT_ID', '123456789012345678') # Ensure Discord client is running before attempting to connect # Presence requires an integer ID, so convert if necessary. print(f"Attempting to connect with Client ID: {CLIENT_ID}") RPC = Presence(CLIENT_ID) try: RPC.connect() print("Connected to Discord RPC") RPC.update(state="Playing a game!", details="Currently in a match", start=int(time.time()), large_image="your_large_image_key", large_text="Large Image Text", small_image="your_small_image_key", small_text="Small Image Text", buttons=[{"label": "Join My Game", "url": "https://example.com/join"}]) print("Presence updated. Will stay active for 30 seconds...") time.sleep(30) # Keep presence active for 30 seconds except Exception as e: print(f"An error occurred: {e}") print("Please ensure Discord is running and your Client ID is correct.") finally: RPC.close() print("Disconnected from Discord RPC.")
Debug
Known issues
gotchaDiscord client must be running. PyPresence connects to Discord via an IPC (Inter-Process Communication) pipe. If the Discord desktop client is not running, PyPresence will fail to connect and raise a `PipeError`.
fix
Ensure the official Discord desktop client is running on your system before running your PyPresence application.
affects: All versions
gotchaIncorrect Client ID or application not public. Your Discord Application ID must be correct and belong to an application you own or have access to. For Rich Presence to be visible to others, the application's 'Public' toggle must be enabled in the Discord Developer Portal.
fix
Verify your Client ID in the Discord Developer Portal (Applications -> Your App -> General Information). Ensure the 'Public' toggle is enabled if you want others to see your presence.
affects: All versions
breakingChanges in IPC pipe detection and closing logic in v4.5.x. Earlier versions might have had issues with reliable connection or proper closing, especially on Windows, leading to 'Pipe Not Found' errors or resources not being released.
fix
Upgrade to pypresence v4.5.2 or newer to benefit from improved IPC pipe detection and connection/disconnection stability. This addresses issues like `get_ipc_path()` when `pipe=0` and broken pipe detection, which were hotfixed in v4.5.2.
affects: Prior to v4.5.2
gotchaUsing `Presence` (sync) in an async context or `AioPresence` (async) in a sync context. While `Presence` is synchronous, `AioPresence` requires an `asyncio` event loop. Mixing them incorrectly can lead to `RuntimeError: Event loop is already running` or `RuntimeError: no current event loop`.
fix
For synchronous applications, use `pypresence.Presence`. For asynchronous applications (e.g., with `discord.py` or `asyncio`), use `pypresence.AioPresence` and ensure your code is `await`ed appropriately within an event loop.
affects: All versions
Errors
Common errors & fixes
pypresence.exceptions.PipeError: Could not find Discord IPC pipe!
The Discord desktop client is not running, or pypresence cannot locate the IPC pipe.
fix
Start the Discord desktop client application. If it's already running, try restarting your Python script or Discord. Ensure you have the latest pypresence version for improved pipe detection.
pypresence.exceptions.InvalidID: The Client ID you provided is invalid.
The Discord Application ID provided to `Presence()` or `AioPresence()` is not a valid 18-19 digit number, or doesn't correspond to an existing Discord application.
fix
Double-check your `CLIENT_ID` in the Discord Developer Portal (https://discord.com/developers/applications). Copy it directly and ensure it's passed as a string or integer.
TypeError: 'str' object cannot be interpreted as an integer
The `CLIENT_ID` was passed as a string where an integer was expected, particularly in older versions or specific parts of the library's internal workings.
fix
Ensure your `CLIENT_ID` is converted to an integer: `Presence(int(CLIENT_ID))` or `AioPresence(int(CLIENT_ID))`. While newer versions might handle string conversion, explicitly converting is safer.
KeyError: 'details'
An invalid key was passed to the `update()` method, or the data structure for presence is incorrect according to Discord's API.
fix
Refer to the pypresence documentation or Discord Rich Presence API for valid keys and their expected types. Common keys include `state`, `details`, `start`, `end`, `large_image`, `large_text`, `small_image`, `small_text`, `buttons`, etc.
Upgrade
Version history
4.6.1latest on PyPI · released Oct 17, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources
pypresence — pip install pypresence · libregistry