A comprehensive Python SDK for managing Marzban panel through its REST API
Project description
SARBAN
A comprehensive Python SDK for managing Marzban panel (Gozargah/Marzban) through its REST API.
📚 Documentation
Quick Reference
Complete Documentation
- Complete English Documentation - Full guide with examples and best practices
- Complete Persian Documentation (فارسی) - راهنمای کامل با مثالها و بهترین روشها
- Complete Chinese Documentation (中文) - 完整指南,包含示例和最佳实践
✨ Features
- ✅ Complete API coverage for all Marzban endpoints
- ✅ Admin management (create, modify, remove admins)
- ✅ User management (CRUD operations, usage tracking)
- ✅ Node management (add, modify, remove, reconnect nodes)
- ✅ Core configuration and statistics
- ✅ System statistics and monitoring
- ✅ User template management
- ✅ Subscription management
- ✅ Comprehensive error handling
- ✅ Type hints for better IDE support
🚀 Installation
pip install sarban
📦 Quick Start
from sarban import SARBAN
from sarban.errors import BadLogin
# Initialize the client
sb = SARBAN(
full_address="https://your-marzban-panel.com:2087",
https=True
)
# Login
try:
sb.login("admin_username", "admin_password")
print("Login successful!")
except BadLogin:
print("Invalid credentials")
📖 API Categories
Authentication
login()- Authenticate and get access token
Admin Management
get_current_admin()- Get current authenticated admincreate_admin()- Create a new adminget_admins()- Get list of adminsmodify_admin()- Modify admin detailsremove_admin()- Remove an admindisable_all_active_users()- Disable all active users under adminactivate_all_disabled_users()- Activate all disabled users under adminreset_admin_usage()- Reset admin usageget_admin_usage()- Get admin usage statistics
User Management
get_client()- Get user by usernameget_client_by_subLink()- Get user by subscription tokenadd_client()- Add a new useredit_client()- Modify existing userdelete_client()- Remove a userget_users()- Get list of users with filtersreset_user_data_usage()- Reset user data usagerevoke_user_subscription()- Revoke user subscriptionget_user_usage()- Get user usage statisticsactive_next_plan()- Activate next plan for userset_owner()- Set owner (admin) for userreset_users_data_usage()- Reset all users data usageget_users_usage()- Get all users usage statisticsget_expired_users()- Get expired usersdelete_expired_users()- Delete expired users
Node Management
get_node_settings()- Get node settingsadd_node()- Add a new nodeget_node()- Get node by IDget_nodes()- Get all nodesmodify_node()- Modify node detailsremove_node()- Remove a nodereconnect_node()- Reconnect a nodeget_usage()- Get nodes usage statistics
Core Management
get_core_stats()- Get core statisticsrestart_core()- Restart the coreget_core_config()- Get core configurationmodify_core_config()- Modify core configuration
System Management
get_system_stats()- Get system statisticsget_inbounds()- Get inbound configurationsget_hosts()- Get proxy hostsmodify_hosts()- Modify proxy hosts
User Template Management
add_user_template()- Add a new user templateget_user_templates()- Get list of user templatesget_user_template()- Get user template by IDmodify_user_template()- Modify user templateremove_user_template()- Remove user template
Subscription Management
user_subscription()- Get user subscriptionuser_subscription_info()- Get subscription infouser_get_usage()- Get subscription usageuser_subscription_with_client_type()- Get subscription by client type
🔧 Error Handling
The SDK provides comprehensive error handling:
from sarban.errors import (
BadLogin,
Unauthorized,
Forbidden,
NotFound,
Conflict,
BadRequest,
ValidationError,
HTTPException
)
try:
user = sb.get_client(username="nonexistent")
except NotFound:
print("User not found")
except Unauthorized:
print("Not authenticated")
except Forbidden:
print("Access denied")
🔗 Subscription Link Generator
from sarban.sub_gen import sub_generator
subscription_link = sub_generator(
userToken="token",
fullAddress="sub.example.com:2096",
verify=True
)
📝 Example Usage
from sarban import SARBAN
sb = SARBAN(full_address="https://panel.example.com:2087", https=True)
sb.login("admin", "password")
# Get all users
users = sb.get_users(limit=10)
# Add a new user
new_user = sb.add_client(
username="test_user",
inboundTag=["VLESS_INBOUND"],
total_gb=10,
expire_time=1735689600
)
# Get system stats
stats = sb.get_system_stats()
print(f"Total users: {stats['total_user']}")
print(f"Online users: {stats['online_users']}")
📄 License
MIT License
👤 Author
liwyd
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🔗 Links
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
sarban-2.0.1.tar.gz
(15.8 kB
view details)
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
sarban-2.0.1-py3-none-any.whl
(19.0 kB
view details)
File details
Details for the file sarban-2.0.1.tar.gz.
File metadata
- Download URL: sarban-2.0.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ab562bb623500bee1dfbdde145b3318bb36425fc90dabcdb4f7b67c94ae5737
|
|
| MD5 |
2d247c0bbca6483f4f67b7c429cab724
|
|
| BLAKE2b-256 |
49ada15a657090b7df9413cc2dba9f18a86391e2b8f6aaf427241c1772bf0b94
|
File details
Details for the file sarban-2.0.1-py3-none-any.whl.
File metadata
- Download URL: sarban-2.0.1-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d895191c261af56f560f0b64dcb4a56a26724934376eedacca9a1a9b89d6af35
|
|
| MD5 |
9d0713db21c6d6a137a6a4ea950ea47a
|
|
| BLAKE2b-256 |
792ca7b653e1876d9b628dacb4b262cc2897ec29f52602a96cc1395406ec49b6
|