Skip to main content

ddapi-rs

A small async Rust library for working with the DDNet and DDStats public APIs.

Features

  • ddnet (default) - DDNet API (ddnet.org)
  • ddstats - DDStats API (ddstats.tw)
  • cache - in-memory cache for responses (uses moka)
  • full - enables ddnet, ddstats, cache

Installation

Default (DDNet only):

cargo add ddapi-rs

Enable DDStats too:

cargo add ddapi-rs -F ddstats

Enable caching:

cargo add ddapi-rs -F cache

Everything:

cargo add ddapi-rs -F full

Usage

The crate is async and uses tokio.

DDNet example (enabled by default):

use ddapi_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let api = DDApi::new();

    // ddnet: player points
    let player = api.player("nameless tee").await?;
    println!("{}: {}", player.player, player.points.points.unwrap_or(0));
    Ok(())
}

DDStats example (requires -F ddstats):

use ddapi_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let api = DDApi::new();

    // ddstats: profile info
    let profile = api.profile("ByFox").await?;
    println!("{} ({})", profile.name, profile.clan.unwrap_or_default());
    Ok(())
}

Optional: only use one API

If you do not want a combined client, you can use DDnetClient / DDstatsClient.

use ddapi_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let ddnet = DDnetClient::new();
    let p = ddnet.player("nameless tee").await?;
    println!("{}: {}", p.player, p.points.points.unwrap_or(0));
    Ok(())
}

Caching (feature cache)

use ddapi_rs::prelude::*;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<()> {
    let mut api = DDApi::new();
    api.set_cache(1000, Duration::from_secs(60 * 5));

    // Will be cached based on URL + TTL
    let _ = api.status().await?;
    Ok(())
}

Custom reqwest client

use ddapi_rs::prelude::*;
use reqwest::Client;

fn main() {
    let client = Client::builder()
        .timeout(std::time::Duration::from_secs(10))
        .build()
        .unwrap();

    let _api = DDApi::new_with_client(client);
}

Python (PyPI package ddapi)

pip install ddapi

The Python package mirrors the Rust API. All methods are async and return typed dataclasses (ddapi.ddnet.* / ddapi.ddstats.*) instead of raw dicts. Fields that may be absent in the API response are None.

import asyncio

import ddapi


async def main():
    api = ddapi.DDApi()

    # ddnet: player points
    player = await api.player("nameless tee")
    print(player.player, player.points.points)  # fields, not dict keys

    # optional data is None - no KeyError
    if player.team_rank is not None:
        print(player.team_rank.rank)

    # ddstats: profile info
    stats = ddapi.DDstatsClient()
    profile = await stats.profile("ByFox")
    print(profile.name, profile.clan)


asyncio.run(main())

Exposed API:

  • DDApi - combined client (DDNet methods take precedence)
  • DDnetClient - DDNet API only: master, custom_master, skins, player, query, query_map, query_mapper, map, releases_map, status, latest_finish, latest_finish_with_latest
  • DDstatsClient - DDStats API only: player, map, maps, profile, teero
  • ddapi.ddnet / ddapi.ddstats - dataclass models (e.g. ddapi.ddnet.Player)
  • DDError - exception raised on API errors
  • __version__ - matches the Rust crate version

Notes:

  • custom_master takes a master server index (1-4).
  • Timestamps arrive as datetime (UTC); dates as date.
  • Optional per-client in-memory cache:
api = ddapi.DDApi()
api.set_cache(10_000, 600)  # capacity, ttl in seconds

Metadata

Release files for ddapi 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ddapi 2.0.3
File Size Uploaded Provenance Actions
ddapi-2.0.3.tar.gz 78.8 kB Without provenance Details for ddapi-2.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ddapi 2.0.3
File Interpreter ABI Platform Actions
ddapi-2.0.3-cp38-abi3-manylinux_2_38_x86_64.whl CPython 3.8 abi3 Linux glibc 2.38+ x86-64 Details for ddapi-2.0.3-cp38-abi3-manylinux_2_38_x86_64.whl

Total release size: 3.2 MB

Release files / ddapi-2.0.3.tar.gz

Download URL ddapi-2.0.3.tar.gz
Size 78.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0edc8dd8af1ab5206d59782c52f1651c6b19b9a03e7eed7ef65c102af2659ab1
BLAKE2b-256 checksum
How to use checksums
27ceb19b7faafd41ce82c2b634c2a5ea231f9bc7fc108f28168e6f1559373ca3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / ddapi-2.0.3-cp38-abi3-manylinux_2_38_x86_64.whl

Download URL ddapi-2.0.3-cp38-abi3-manylinux_2_38_x86_64.whl
Size 3.1 MB
Tags CPython 3.8 Linux glibc 2.38+ x86-64 abi3
SHA-256 checksum
How to use checksums
2091502b0f77a7904c5877afa630912fcc0a4fcd694c8d1ab43e3f05be43de9c
BLAKE2b-256 checksum
How to use checksums
c65e0dcd702a842a40b7bfcccb80c1a3a827ecf691f732041cc20c69ddff9665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Security for ddapi 2.0.3

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.

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page