User-friendly async SDK for the Marzban API.
Project description
aiomarzban
Async SDK for the Marzban API based on aiohttp and pydantic. This library is fully compatible with Marzban version 0.8.4 and supports all panel methods.
Features
- Async library for non-blocking operations
- Automatic under-the-hood access token management
- All functions implemented as native class methods
- Extensive test coverage for most of the code
- Default values can be provided for user creation
- Simplified user creation through method parameters
- Automatic conversion of gigabytes to bytes
- Custom methods for tailored functionality
Installation
pip install aiomarzban --upgrade
Examples
from aiomarzban import MarzbanAPI, UserDataLimitResetStrategy, UserStatusModify
marzban = MarzbanAPI(
address="https://my_domain.com/",
username="admin",
password="super_secret_password",
default_proxies={"vless": {"flow": ""}},
)
async def main():
# Create admin
new_admin = await marzban.create_admin(username="new_admin", password="12345678", is_sudo=False)
print("New admin: ", new_admin)
# Create user
new_user = await marzban.add_user(
username="user1",
days=90,
data_limit=100, # In GB
data_limit_reset_strategy=UserDataLimitResetStrategy.month,
)
print("New user: ", new_user)
# Modify user
modified_user = await marzban.modify_user(
username="user1",
status=UserStatusModify.disabled,
)
print("Modified user: ", modified_user)
# Add days of subscription to user
modified_user = await marzban.user_add_days("user1", 60)
print("Modified user: ", modified_user)
# Get users
users = await marzban.get_users(offset=0, limit=100)
print("Users: ", users)
# Create node
new_node = await marzban.add_node(
name="New node",
address="8.8.8.8",
)
print("New node: ", new_node)
# Modify node
modified_node = await marzban.modify_node(
node_id=new_node.id,
usage_coefficient=0.2,
)
print("Modified node: ", modified_node)
Test coverage
Warning: It is highly not recommended to run tests on a production server!
- Admin
- Core
- Node
- Subscription
- System
- User template
- User
To run tests:
Create .env file with panel information
pytest tests/
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Make your changes.
- Run tests to ensure everything works (optional).
- Submit a pull request.
Tasks
- Fix tests to avoid freezing
- Tests for subscription
Timeout for requestsRetries for requests- More custom useful methods
Create library in PyPi- Find and remove bugs :)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For questions, suggestions, or feedback, please reach out to my telegram or mestepanik@gmail.com.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiomarzban-1.0.3.tar.gz.
File metadata
- Download URL: aiomarzban-1.0.3.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73cc7424d7d6b5e0155c4b3f433d66426517fe7fcc5e12e3b36ae6648d14186e
|
|
| MD5 |
3fc5e35e10477da2dd8a2e41e1ac6faf
|
|
| BLAKE2b-256 |
fd4d6996098abd8f7015c767f041402e2aa9e8ddc197fddcc1e131b4b7fcd29d
|
File details
Details for the file aiomarzban-1.0.3-py3-none-any.whl.
File metadata
- Download URL: aiomarzban-1.0.3-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e758150c11108459218287a43d311daf2cc1dbb87664c4f5a2c8dc484135ee76
|
|
| MD5 |
7e2944744de52339c53fb1e3a1a14c7e
|
|
| BLAKE2b-256 |
7cd78133046eca2dcb0b64c50394c235b525d0449619eb686843992dc4d43231
|