Python SDK [community]
コミュニティ SDK
この SDK はコミュニティによって完全にメンテナンスされています。
Remnawave Python SDK は、RestAPI タイプとの便利なインタラクションのためのライブラリです。
✨ 主な機能
- コントローラーベースの設計:柔軟性のために機能を個別のコントローラーに分割。必要なものだけ使用できます!
- Pydantic モデル:より高い信頼性のための強く型付けされたリクエストとレスポンス。
- 高速シリアライゼーション:効率的な JSON 処理のための orjson を使用。
- モジュール式の使用:必要に応じて個々のコントローラーまたは完全な 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 をウェブサーバーとして使用する例
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