mirror of
https://github.com/remnawave/panel.git
synced 2026-04-04 19:41:17 +00:00
139 lines
3.9 KiB
Markdown
139 lines
3.9 KiB
Markdown
---
|
|
sidebar_position: 2
|
|
title: Python SDK [community]
|
|
---
|
|
|
|
import Admonition from '@theme/Admonition';
|
|
import { FaPeopleGroup } from "react-icons/fa6";
|
|
|
|
<Admonition type="note" icon={<FaPeopleGroup />} title="Community SDK">
|
|
This SDK is fully community-maintained.
|
|
</Admonition>
|
|
|
|
Remnawave Python SDK is a library for convenient interaction with the RestAPI types.
|
|
|
|
✨ Key Features
|
|
|
|
- Controller-based design: Split functionality into separate controllers for flexibility. Use only what you need!
|
|
- Pydantic models: Strongly-typed requests and responses for better reliability.
|
|
- Fast serialization: Powered by orjson for efficient JSON handling.
|
|
- Modular usage: Import individual controllers or the full SDK as needed.
|
|
- Custom HTTP Client Support: You can pass your own httpx.AsyncClient with custom headers to bypass various checks.
|
|
- Caddy Token Integration: Direct support for passing the caddy_token during SDK initialization.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install remnawave
|
|
```
|
|
|
|
## Usage
|
|
|
|
<details>
|
|
<summary>Example usage</summary>
|
|
|
|
```python
|
|
import os
|
|
import asyncio
|
|
|
|
from remnawave import RemnawaveSDK # Updated import for new package
|
|
from remnawave.models import ( # Updated import path
|
|
UsersResponseDto,
|
|
UserResponseDto,
|
|
GetAllConfigProfilesResponseDto,
|
|
CreateInternalSquadRequestDto
|
|
)
|
|
|
|
async def main():
|
|
# URL to your panel (ex. https://vpn.com or http://127.0.0.1:3000)
|
|
base_url: str = os.getenv("REMNAWAVE_BASE_URL")
|
|
# Bearer Token from panel (section: API Tokens)
|
|
token: str = os.getenv("REMNAWAVE_TOKEN")
|
|
|
|
# Initialize the SDK
|
|
remnawave = RemnawaveSDK(base_url=base_url, token=token)
|
|
|
|
# Fetch all users
|
|
response: UsersResponseDto = await remnawave.users.get_all_users()
|
|
total_users: int = response.total
|
|
users: list[UserResponseDto] = response.users
|
|
print("Total users: ", total_users)
|
|
print("List of users: ", users)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
```
|
|
|
|
</details>
|
|
|
|
<details>
|
|
<summary>Example usage with Caddy as web-server</summary>
|
|
|
|
```python
|
|
import os
|
|
import asyncio
|
|
|
|
from remnawave import RemnawaveSDK # Updated import for new package
|
|
from remnawave.models import ( # Updated import path
|
|
UsersResponseDto,
|
|
UserResponseDto,
|
|
GetAllConfigProfilesResponseDto,
|
|
CreateInternalSquadRequestDto
|
|
)
|
|
|
|
async def main():
|
|
# URL to your panel (ex. https://vpn.com or http://127.0.0.1:3000)
|
|
base_url: str = os.getenv("REMNAWAVE_BASE_URL")
|
|
# Bearer Token from panel (section: API Tokens)
|
|
token: str = os.getenv("REMNAWAVE_TOKEN")
|
|
# Bearer Token for Caddy Auth
|
|
caddy_token = os.getenv("CADDY_TOKEN_AUTH")
|
|
|
|
# Initialize the SDK
|
|
remnawave = RemnawaveSDK(base_url=base_url, token=token, caddy_token=caddy_token)
|
|
|
|
# Fetch all users
|
|
response: UsersResponseDto = await remnawave.users.get_all_users()
|
|
total_users: int = response.total
|
|
users: list[UserResponseDto] = response.users
|
|
print("Total users: ", total_users)
|
|
print("List of users: ", users)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
```
|
|
|
|
</details>
|
|
|
|
<details>
|
|
<summary>Example usage with custom client</summary>
|
|
|
|
```python
|
|
import os
|
|
import asyncio
|
|
import httpx
|
|
from remnawave import RemnawaveSDK
|
|
|
|
async def main():
|
|
base_url = os.getenv("REMNAWAVE_BASE_URL")
|
|
token = os.getenv("REMNAWAVE_TOKEN")
|
|
|
|
# Custom client with headers
|
|
async with httpx.AsyncClient(headers={"hello": "world"}) as client:
|
|
# Initialize SDK with a custom client
|
|
remnawave = RemnawaveSDK(base_url=base_url, token=token, client=client)
|
|
|
|
# Fetch all users
|
|
response = await remnawave.users.get_all_users_v2()
|
|
print("Total users:", response.total)
|
|
|
|
asyncio.run(main())
|
|
```
|
|
|
|
</details>
|
|
|
|
## 🛠️ Project Links
|
|
|
|
- **GitHub Repository:** [Remnawave API on GitHub](https://github.com/remnawave/python-sdk)
|
|
- **Authors:** [Artem (sm1ky)](https://github.com/sm1ky), [Kesevone](https://github.com/kesevone)
|