Skip to main content

A flexible, feature-rich API client for the ER:LC private server API.

Project description

prc-client

prc-client is a flexible, feature-rich API client for the ER:LC private server API. This client provides a simple and intuitive interface for interacting with ER:LC private servers with detailed data models, typing, comprehensive error handling, and a high-performance architecture.

This library aims to provide all the functionality you need without overwhelming developers with unnecessary features or complexity. prc-client stays lightweight, allowing for full control over your development process - whether you're building a simple automation script to fully-featured complex application integrating with the PRC API.

Key Features

  • 100% coverage of all V1 and V2 API endpoints
  • Full support for the event webhook API
  • Support for both synchronous and asynchronous applications
  • Automatic rate limit handling
  • Intuitive developer interface allows for rapid prototyping and high development experience
  • High performance - built on top of HTTPX for HTTP requests and Pydantic for data validation
  • Detailed docstring documentation and examples
  • Comprehensive error handling and logging

Installation

Install prc-client using pip:

pip install prc-client

Optionally install additional dependencies:

pip install prc-client[events,fastapi]

Quick Start

Import the prc module and create a client instance.

import prc

client = prc.v2.Client()
Or asynchronously...
import prc

client = prc.v2.AsyncClient()

Get a server with configurable parameters, or get a BundledServer with all available API data.

import prc

client = prc.v2.Client()

# Contains only the specified data
server = client.get_server(players=True, vehicles=True)
# Contains all available data
bundled_server = client.get_bundled_server()
Or asynchronously...
import prc

async def main():
    client = prc.v2.AsyncClient()

    # Contains only the specified data
    server = await client.get_server(players=True, vehicles=True)
    # Contains all available data
    bundled_server = await client.get_bundled_server()

Send a command to the server using the send_command method and cmd factory to build commands.

import prc
from prc import cmd

client = prc.v2.Client()

# Contains only the specified data
server = client.get_server(players=True, vehicles=True)
# Contains all available data
bundled_server = client.get_bundled_server()

# Send a PM to all players
client.send_command(cmd.pm(server.players, "Welcome to the server!"))
Or asynchronously...
import prc
from prc import cmd

async def main():
    client = prc.v2.AsyncClient()

    # Contains only the specified data
    server = await client.get_server(players=True, vehicles=True)
    # Contains all available data
    bundled_server = await client.get_bundled_server()

    # Send a PM to all players
    await client.send_command(cmd.pm(server.players, "Welcome to the server!"))

Let's set up a router with a simple command handler to receive requests from PRC.

import prc
from prc import cmd
from prc.events import Router, Context

client = prc.v2.Client()
# Create a router
router = Router(client)

# Define a command handler to run when the command ;myid / ;id / ;whoami is sent
@router.on.command("myid", "id", "whoami")
def handle_myid_command(ctx: Context):
    ctx.reply(f"Your ID is: {ctx.user.id}")

# This command handler runs when any command is received
@router.on.any_command()
def handle_any_command(ctx: Context):
    print(f"User {ctx.user.id} sent command '{ctx.command.command}' with arguments {ctx.command.arguments}")

# Contains only the specified data
server = client.get_server(players=True, vehicles=True)
# Contains all available data
bundled_server = client.get_bundled_server()

# Send a PM to all players
client.send_command(cmd.pm(server.players, "Welcome to the server!"))
Or asynchronously...
import prc
from prc import cmd
from prc.events import Router, Context

client = prc.v2.AsyncClient()
# Create a router
router = Router(client)

# Define a command handler to run when the command ;myid / ;id / ;whoami is sent
@router.on.command("myid", "id", "whoami")
async def handle_myid_command(ctx: Context):
    await ctx.areply(f"Your ID is: {ctx.user.id}")

# This command handler runs when any command is received
@router.on.any_command()
def handle_any_command(ctx: Context):
    print(f"User {ctx.user.id} sent command '{ctx.command.command}' with arguments {ctx.command.arguments}")

async def main():
    # Contains only the specified data
    server = await client.get_server(players=True, vehicles=True)
    # Contains all available data
    bundled_server = await client.get_bundled_server()

    # Send a PM to all players
    await client.send_command(cmd.pm(server.players, "Welcome to the server!"))
FastAPI application code

See the FastAPI documentation for more information on how to use FastAPI.

from fastapi import FastAPI, Request, Response, BackgroundTasks

app = FastAPI()

@app.post("/your/endpoint")
async def prc_webhook(request: Request, background_tasks: BackgroundTasks):
    status = await router.handle_fastapi_request(request, background_tasks)
    return Response(status_code=status)

Check out the examples for more information on specific use cases.

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

prc_client-1.1.0.tar.gz (58.2 kB view details)

Uploaded Source

Built Distribution

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

prc_client-1.1.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file prc_client-1.1.0.tar.gz.

File metadata

  • Download URL: prc_client-1.1.0.tar.gz
  • Upload date:
  • Size: 58.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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 prc_client-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fab3b9eca998a83b4ec130bd41db94b665300bd75338f32a30c7adaac2a19a03
MD5 cb5d94e8b7a72993a162c31b0c7c44c5
BLAKE2b-256 1d52e73c3b08e8e9539a346231ec558f8577cf467f4390d9028bb4c5f7880e08

See more details on using hashes here.

File details

Details for the file prc_client-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: prc_client-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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 prc_client-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efe4ec289662e8a85efcf721d662c5cd697af02f4718cb8027867170f93efe89
MD5 a6fad69e72229acaf60aa77fc93f2bab
BLAKE2b-256 587ba515c6f00529789ea24eacde8c41340e8b28bc5e82c9cf9dc379830e8928

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