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.0.tar.gz (67.1 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.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lanyard_py-2.0.0.tar.gz
  • Upload date:
  • Size: 67.1 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.0.tar.gz
Algorithm Hash digest
SHA256 2ec943c2f0e11e284247613fe7f437a9d86bdd73c311965f47f7b864466bc0c3
MD5 b842c4084a18e027de0bd63f2b301ec6
BLAKE2b-256 51f192ba8cb7ed0d053ae246a5d7355ccabc21954ac38d2b9bd7b306bffae760

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lanyard_py-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfef3e1d9b0b281008dd60050155868cc2f0b44d072343d2a15b379597d7461c
MD5 6207ed8929654297a54f4794fbf18291
BLAKE2b-256 7382d7afeb1ae9700d8f8207d50606898df8e0c77ff83c0f466279aaef86d6d2

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