rw-sdk
Full Python SDK for the Remnawave panel API. Every endpoint, typed, sync and async.
pip install rw-sdk
from rw_sdk import Remnawave
with Remnawave("https://panel.example.com", token="...") as rw:
user = rw.users.create_user(
username="alice",
expire_at=datetime(2027, 1, 1, tzinfo=timezone.utc),
traffic_limit_bytes=100 * 1024**3,
)
print(user.subscription_url, user.status)
for u in rw.users.iter_users(): # pages fetched automatically
print(u.username, u.user_traffic.used_traffic_bytes)
| API version | 3.4.11 — 218 operations across 28 resources, all implemented |
| Models | 672 generated classes (588 pydantic v2 models + 84 enums), named after Remnawave's own zod contract schemas |
| Async | every method mirrored on AsyncRemnawave |
| Verified | offline contract tests + live integration run against a real 3.4.11 panel |
Authentication
Use an API token created on the panel's API Tokens page. That is the supported mode for automation and what everything here is built around.
rw = Remnawave("https://panel.example.com", token="eyJhbGci...")
11 endpoints an API token cannot reach
An API token always carries role API. Three controllers declare @Roles(ROLE.ADMIN)
without ROLE.API, so calling them with a token returns 403 E000 no matter its
scopes — verified against a live 3.4.11 panel:
| Endpoints | Why |
|---|---|
rw.api_tokens.* (4) |
tokens are minted from the panel UI or an admin session |
rw.passkeys.* (5) |
passkey management is a dashboard flow |
rw.settings.* (2) |
/api/remnawave-settings is admin-only |
They are still generated — this SDK covers all 218 operations — and each one says so in
its docstring. rw_sdk.ENDPOINTS carries an admin_only flag if you want to check
programmatically.
Everything else (users, nodes, hosts, squads, config profiles, subscriptions, stats, HWID, connections, infra billing, snippets, templates …) works with an API token.
Admin JWT, if you need those 11
auth.login returns an admin-role JWT, which JwtDefaultGuard rejects unless the
request also carries X-Remnawave-Client-Type: browser (def-jwt-guard.ts).
The SDK does not send that header — it targets API tokens. Supply it yourself if
you need the admin path:
rw = Remnawave(
"https://panel.example.com",
headers={"X-Remnawave-Client-Type": "browser"},
)
rw.set_token(rw.auth.login(username="admin", password="...").access_token)
token = rw.api_tokens.create_api_token(name="ci", expires_in_days=90, scopes=["users:*"])
print(token.token) # returned once
Without the header every call returns 403. Per-endpoint API-token scopes are in each
method's docstring.
The HTTPS/proxy requirement
In production Remnawave destroys the socket of any request that lacks
x-forwarded-for or does not carry x-forwarded-proto: https
(proxy-check.middleware.ts) — you get a connection reset, not an HTTP error.
proxy_headers="auto" (the default) sends those headers only when the target looks
like a direct connection — plain http://, or a loopback/private host. Behind a real
reverse proxy the headers already exist, and forging x-forwarded-for there would
corrupt the panel's client-IP accounting, so they are left alone.
Remnawave("http://127.0.0.1:3000", token=t) # headers sent
Remnawave("https://panel.example.com", token=t) # not sent
Remnawave("https://panel.example.com", token=t, proxy_headers="always") # forced
A reset connection is surfaced as ProxyRestrictionError with the fix in the message.
Pagination
Ten endpoints paginate (7 offset, 3 cursor). Each gets an iterator that handles the offset or cursor for you:
for user in rw.users.iter_users(page_size=500): # offset: start/size/total
...
for user in rw.users.iter_users_stream(page_size=1000): # cursor: nextCursor/hasMore
...
async for device in arw.hwid.iter_all_users(): # same on the async client
...
The underlying single-page calls (rw.users.get_users(start=..., size=...)) are still
there when you want them.
Filtering and sorting
Four list endpoints take TanStack-table style filters. The panel reads each as one
JSON-encoded string (JSON.parse), and this SDK serialises them for you:
from rw_sdk.models import TanstackQueryFilter, TanstackQuerySorting
page = rw.users.get_users(
filters=[TanstackQueryFilter(id="username", value="alice")],
filter_modes={"username": "startsWith"},
sorting=[TanstackQuerySorting(id="createdAt", desc=True)],
)
# plain dicts work too, and iterators forward the filter
for user in rw.users.iter_users(filters=[{"id": "tag", "value": "VIP"}]):
...
Modes: equals, startsWith, endsWith, greaterThan, greaterThanOrEqualTo,
lessThan, lessThanOrEqualTo, between. Anything else falls through to a contains
match rather than erroring. A sorting id is passed straight to the query builder, so
an unknown column returns 500.
Omitted vs null
Remnawave's PATCH endpoints distinguish an absent key ("leave unchanged") from an
explicit null ("clear this field"). Passing None means null; leaving an argument
out sends nothing.
rw.users.update_user(id=u.id, description="new") # tag untouched
rw.users.update_user(id=u.id, tag=None) # tag cleared
Raw subscriptions
GET /api/sub/{shortUuid} and /api/sub/{shortUuid}/{clientType} are written straight
to the socket by the panel — the body may be base64, YAML, JSON or an encrypted blob
depending on the matched response rule, and the useful metadata is in the headers.
They return a RawSubscription instead of a model:
raw = rw.sub.get_subscription(user.short_uuid)
raw.text # decoded body
raw.user_info # {'upload': 0, 'download': 0, 'total': ..., 'expire': ...}
raw.headers["profile-title"]
from rw_sdk.models import ClientType
rw.sub.get_subscription_by_client_type(user.short_uuid, ClientType.SINGBOX).json()
Errors
from rw_sdk import errors
try:
rw.users.get_user_by_id(user_id)
except errors.NotFoundError as e:
print(e.status_code, e.error_code, e.error) # 404 A025 ErrorCode.USER_NOT_FOUND
except errors.ValidationError as e:
for issue in e.errors: # zod field-level failures
print(issue["path"], issue["message"])
except errors.PermissionDeniedError:
... # role or token scope too narrow
except errors.APIConnectionError:
... # network, timeout, or proxy check
All 255 panel error codes are available as errors.ErrorCode. GET, HEAD and OPTIONS are
retried twice with jittered backoff by default (max_retries=) on 408, 409, 429, uncoded
500/502/503/504 and connection failures (a coded 5xx is a deliberate failure, see below).
Writes are never retried: after a lost response, check the operation's outcome before
sending it again.
Transport
Built on niquests — sync and async from one library, HTTP/1.1, HTTP/2 and HTTP/3.
Measured against a real 2.8.1 panel, same workload, versus the same SDK on httpx:
| httpx | niquests | |
|---|---|---|
| one user by name | 1.74 ms | 1.68 ms |
| page of 300 users | 14.56 ms | 10.73 ms |
| 100 concurrent lookups | 176.6 ms | 42.7 ms |
The concurrency gap is the one that matters — httpx's per-request overhead multiplies
under asyncio.gather, and raising its connection limits makes it worse, not better.
benchmarks/http_clients.py reproduces the comparison across httpx, urllib3, rnet,
curl_cffi, aiohttp and aiosonic on your own hardware and latency.
Pass your own session to tune it:
import niquests
Remnawave(url, token=t, http_client=niquests.Session(base_url=url, pool_maxsize=100))
Headers and the bearer token go with each request, not into the session, so clients sharing one
session keep their own tokens; an authorization header set on the session itself is never sent.
Escape hatch
Newer panel than this SDK? Call anything directly — auth, retries, headers and error mapping still apply:
resp = rw.request("POST", "/api/some/new/endpoint", json={"foo": 1})
resp.json()
Versioning
The SDK version tracks the panel API version it was generated from.
| Branch | Targets |
|---|---|
main |
latest released Remnawave |
2.8.1 |
pinned to panel 2.8.1 |
pip install "rw-sdk==2.8.1.*" # stay on the 2.8.1 API
The X.Y.Z part is the panel API version. A .postN suffix means an SDK-only fix
against that same API — 2.8.1 < 2.8.1.post1 < 2.8.2.
extra="allow" on every model means a panel that adds fields will not break your
client; a panel that removes or retypes them can, which is what the pinned branches
are for.
How this is built
The Remnawave OpenAPI spec is generated by nestjs-zod and inlines every schema — 309
components, nearly all with no $refs between them (since 3.3.2 only the 54 host
schemas reference others). Point a stock generator at it and you get
either ~20 mutually-incompatible copies of the User entity (openapi-python-client) or
deduped-but-anonymous Response19 classes (datamodel-code-generator). Neither unwraps
the {"response": ...} envelope every endpoint uses.
So the pipeline is three stages:
codegen/refify.pyrewrites the spec into one with real$refs, deduping shapes by structural fingerprint and naming them from Remnawave's own zod contract models (libs/contract/models/*.schema.ts, including.extend()/.merge()composition).- datamodel-code-generator turns that into pydantic v2 models. Model generation is a solved problem; we do not reimplement it.
codegen/generate.pyemits the layer no generator provides — resource classes, envelope unwrapping, auto-paging iterators, raw-subscription handling, and scope docs read out of the contract sources.
Regenerate for a new panel release:
git clone --depth 1 --branch 3.4.11 https://github.com/remnawave/backend /tmp/rw
docker run --rm --entrypoint cat remnawave/backend:3.4.11 /opt/app/openapi.json \
| python3 -m json.tool --indent 2 --no-ensure-ascii > specs/openapi-3.4.11.json
pip install "rw-sdk[codegen]"
python3 codegen/generate.py specs/openapi-3.4.11.json --backend /tmp/rw
pytest
codegen/spec_patches.py also adds hideTrafficLimit to the create/update user bodies: a field
of the Akenai panel (remnawave-rs), not of upstream. The panel still enforces the limit and only
stops showing it to the subscription owner; upstream ignores the key.
What the spec gets wrong
The generated surface matches all 218 operations in the 3.4.11 OpenAPI document.
Offline checks compare every operation; live tests exercise the client against a
panel at the same tag. Where the spec is wrong, and how it is handled:
- The TanStack parameters' encoding is not expressible in OpenAPI. The document
declares
filters/filterModes/sorting, but the panel reads each as one JSON-encoded string (z.preprocess(str => JSON.parse(str), ...)), not as bracketed or repeated query values.codegen/spec_patches.pytags every structured query parameter and the client serialises them withjson.dumps. - Regex
patterns are stamped on every uuid/date/email field. Validating the panel's own output against them buys nothing and a string pattern cannot even apply to a parseddatetime, sorefifydrops them — same policy asformat: uuid. templateJsonisz.nullable(z.unknown())— optional in zod, but emitted as required, while the panel omits the key entirely. Trusting the spec makessubscription_template.get_all_templates()raise on a real panel.z.unknown()-shaped properties are dropped fromrequired.type: number(zodz.number()without.int()) covers ids and byte counters. Mapped toint | floatso an 8-byte traffic total stays exact instead of becoming a float.- A short page is not the last page.
getAllSubscriptionsskips users whose subscription fails to build but still reportstotalas the user count, so a page can come back short — or empty — with rows remaining. The iterators advance by the requested page size and stop ontotal, never on a short page. - 11 endpoints are unreachable with an API token — see 11 endpoints an API token cannot reach above.
- The client accepts any 2xx and maps exceptions by HTTP status, never by the documented response list — nothing is gained by enforcing it client-side.
- A 5xx carrying an
errorCodeis not retried. The exception filters stamp that field only onto deliberate failures — config-profile (A112/A061) and settings (A199/A193) validation both surface as coded 500s — so retrying only delays the error. The rest of the retry policy is under Errors. - The two raw subscription endpoints are
@Res()handlers with no schema; they are special-cased rather than typed asAny.
Running against a local panel
git clone --depth 1 --branch 3.4.11 https://github.com/remnawave/backend /tmp/rw
cd /tmp/rw && cp .env.sample .env # set APP_SECRET
docker compose -f docker-compose-prod.yml up -d
export RW_SDK_TEST_URL=http://127.0.0.1:3000
export RW_SDK_TEST_TOKEN=... # an API token from the panel
export RW_SDK_TEST_ADMIN_TOKEN=... # optional: admin JWT, unlocks the admin-only tests
pytest tests/test_live.py
The panel runs in production mode, so requests need the forwarded headers — the live
tests pass proxy_headers="always".
License
MIT. Remnawave itself is AGPL-3.0; this is an independent client, not affiliated with the Remnawave project.
Metadata
Release files for rw-sdk 3.4.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rw_sdk-3.4.11.tar.gz | 645.9 kB | With provenance | Details for rw_sdk-3.4.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rw_sdk-3.4.11-py3-none-any.whl | Python 3 | none | any | Details for rw_sdk-3.4.11-py3-none-any.whl |
Total release size: 754.7 kB
Release files / rw_sdk-3.4.11.tar.gz
| Download URL | rw_sdk-3.4.11.tar.gz |
|---|---|
| Size | 645.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c685d73ba7ddc60c0684b31aa5988abecd49b9957c160838c2368e7f872d74bf
|
|
BLAKE2b-256 checksum How to use checksums |
eb8daaff2c1df51ede05a3529930cad8cb2218208526ea32ac4973014e664857
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logRelease files / rw_sdk-3.4.11-py3-none-any.whl
| Download URL | rw_sdk-3.4.11-py3-none-any.whl |
|---|---|
| Size | 108.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfd095a3ddd6b95784170951077187bede41f810b21cb5f45ba56c488578e68b
|
|
BLAKE2b-256 checksum How to use checksums |
cdc2fe85fcf655f6ae54d8227ba8d69da52ef6608ee76243850066c423be65cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logSecurity for rw-sdk 3.4.11
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rw_sdk-3.4.11.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.
Transparency logA 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.