lanyard.py is a modern and fully asynchronous wrapper for Lanyard API (REST & WebSocket) written in Python 3.12+.
Installation
# Install with httpx support
pip install "lanyard.py[httpx]"
# or (To work with WebSocket, select aiohttp)
pip install "lanyard.py[aiohttp]"
Quick Start
REST API
import asyncio
import logging
import sys
from lanyard import LanyardClient, LanyardData, HttpxProvider
async def main():
async with LanyardClient(HttpxProvider()) as client:
data: LanyardData = await client.get_user(338718840873811979)
print(data["discord_user"]["username"])
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
WebSocket
import asyncio
import logging
import sys
from lanyard import LanyardClient, AiohttpProvider
async def main():
async with LanyardClient(AiohttpProvider()) as client:
async for data in client.subscribe(338718840873811979):
print(data["discord_user"]["username"])
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
Available Methods
REST
| Method | Description | Auth Required |
|---|---|---|
get_user(user_id) |
Retrieve presence data for a specific user. | No |
get_me() |
Retrieve presence data for the authenticated user. | Yes |
set_kv(user_id, key, value) |
Set a single key-value pair in Lanyard KV. | Yes |
update_kv(user_id, data) |
Bulk update/merge multiple KV pairs. | Yes |
delete_kv(user_id, key) |
Delete a key from Lanyard KV. | Yes |
WebSocket
| Method | Description |
|---|---|
subscribe(*user_ids) |
Subscribe to one or more user IDs. |
subscribe(subscribe_to_all=True) |
Subscribe to all users monitored by Lanyard. |
Error Handling
The library uses a hierarchy of exceptions for granular error management:
LanyardError: Base exception for all library-related errors.LanyardAPIError: Raised when the API returns an error or a non-200 status code.LanyardProviderError: Raised for network-related issues (timeouts, connection failures).LanyardUnauthorizedError: Raised when a token is missing or invalid.LanyardSocketError: Base class for WebSocket-related errors.LanyardSocketCloseError: Raised when the server closes the WebSocket with a specific error code.
Examples
Detailed implementation examples are available in the example/ directory:
- Basic REST usage
- Real-time monitoring via WebSockets
Metadata
Release files for lanyard-py 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lanyard_py-2.0.1.tar.gz | 67.2 kB | Without provenance | Details for lanyard_py-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lanyard_py-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for lanyard_py-2.0.1-py3-none-any.whl |
Total release size: 81.2 kB
Release files / lanyard_py-2.0.1.tar.gz
| Download URL | lanyard_py-2.0.1.tar.gz |
|---|---|
| Size | 67.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c0407fe5b808df6184c746208da17bfbee73cdc8ebe2912c454040ae1e97b28
|
|
BLAKE2b-256 checksum How to use checksums |
7e61a6f936aca0d29c4a2f604664220185f6dfd5629e2093be3c5886b7b5ed8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / lanyard_py-2.0.1-py3-none-any.whl
| Download URL | lanyard_py-2.0.1-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fadbdb5925e57cdfd875a182566d787a779f338e4f4e2b0c5e54bfb61f197aa
|
|
BLAKE2b-256 checksum How to use checksums |
b2edd85a4ee2a71da63715ddfa183d104e6a5724973cd875ccb60f0b3402f31d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for lanyard-py 2.0.1
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.