Skip to main content

lanyard-py is a modern and fully asynchronous wrapper for Lanyard API written in Python 3.12+.

Project description

Lanyard.py

lanyard.py is a modern and fully asynchronous wrapper for Lanyard API (REST & WebSocket) written in Python 3.12+.

PyPI - Version GitHub License GitHub contributors


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

Made with ❤️ in Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lanyard_py-2.0.1.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lanyard_py-2.0.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file lanyard_py-2.0.1.tar.gz.

File metadata

  • Download URL: lanyard_py-2.0.1.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for lanyard_py-2.0.1.tar.gz
Algorithm Hash digest
SHA256 3c0407fe5b808df6184c746208da17bfbee73cdc8ebe2912c454040ae1e97b28
MD5 742a67ffedb054ef18e671732d310982
BLAKE2b-256 7e61a6f936aca0d29c4a2f604664220185f6dfd5629e2093be3c5886b7b5ed8d

See more details on using hashes here.

File details

Details for the file lanyard_py-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: lanyard_py-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for lanyard_py-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fadbdb5925e57cdfd875a182566d787a779f338e4f4e2b0c5e54bfb61f197aa
MD5 d0bba52b40c81b2c04c083cf9cc6cf8c
BLAKE2b-256 b2edd85a4ee2a71da63715ddfa183d104e6a5724973cd875ccb60f0b3402f31d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page