Roux is a simple, (a)synchronous Reddit API wrapper implemented in Rust.
To create an OAuth client with the Reddit API, use the Reddit
class.
use roux::Reddit;
let client = Reddit::new("USER_AGENT", "CLIENT_ID", "CLIENT_SECRET")
.username("USERNAME")
.password("PASSWORD")
.login()
.await;
let me = client.unwrap();
It is important that you pick a good user agent. The ideal format is platform:program:version (by /u/yourname)
, e.g. macos:roux:v2.0.0 (by /u/beanpup_py)
. This will authticate you as the user given in the username function.
Using the OAuth client, you can:
use roux::Reddit;
let client = Reddit::new("USER_AGENT", "CLIENT_ID", "CLIENT_SECRET")
.username("USERNAME")
.password("PASSWORD")
.login()
.await;
let me = client.unwrap();
me.submit_text("TEXT_TITLE", "TEXT_BODY", "SUBREDDIT").await?;
use roux::Reddit;
let client = Reddit::new("USER_AGENT", "CLIENT_ID", "CLIENT_SECRET")
.username("USERNAME")
.password("PASSWORD")
.login()
.await;
let me = client.unwrap();
me.submit_link("LINK_TITLE", "LINK", "SUBREDDIT").await?;
There are also read-only modules that don't need authentication:
You can use a blocking (synchronous) API instead of tokio by enabling the blocking
feature.
[dependencies]
roux = { version = "2", features = ["blocking"] }
use roux::Reddit;
let client = Reddit::new("USER_AGENT", "CLIENT_ID", "CLIENT_SECRET")
.username("USERNAME")
.password("PASSWORD")
.login();
let me = client.unwrap();
me.submit_link("LINK_TITLE", "LINK", "SUBREDDIT");
roux-stream
provides an API for continuously streaming new submissions and comments
Roux is not in active development but is still being maintained and currently covers the most common and useful endpoints. If you see something missing or encounter a bug, feel free to open an issue or create a pull request.
Roux is licensed under the MIT license (see LICENSE file).