Python SDK [community]
社群 SDK
此 SDK 完全由社群維護。
Remnawave Python SDK 是一個用於便捷與 RestAPI 類型互動的函式庫。
✨ 主要特性
- 基於控制器的設計:將功能分割到獨立的控制器中以獲得更大靈活性。只使用你需要的部分!
- Pydantic 模型:強型別的請求和回應,提供更好的可靠性。
- 快速序列化:由 orjson 驅動,實現高效的 JSON 處理。
- 模組化使用:根據需要匯入獨立控制器或完整 SDK。
- 自訂 HTTP 客戶端支援:可以傳入帶有自訂請求標頭的 httpx.AsyncClient,以繞過各種檢查。
- Caddy 令牌整合:直接支援在 SDK 初始化時傳入 caddy_token。
安裝
pip install remnawave
使用
使用範例
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())
以 Caddy 為 Web 伺服器的使用範例
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())
使用自訂客戶端的範例
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())
專案連結
- GitHub 儲存庫: GitHub 上的 Remnawave API
- 作者: Artem (sm1ky), Kesevone