Metadata-Version: 2.4
Name: marzbanapilib
Version: 0.2.0
Summary: A modern async Python client library for Marzban VPN panel API
Home-page: https://github.com/DeepPythonist/marzbanapilib
Author: Mohammad Rasol Esfandiari
Author-email: Mohammad Rasol Esfandiari <mrasolesfandiari@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Mohammad Rasol Esfandiari
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/DeepPythonist/marzbanapilib
Project-URL: Bug Tracker, https://github.com/DeepPythonist/marzbanapilib/issues
Project-URL: Documentation, https://github.com/DeepPythonist/marzbanapilib#readme
Project-URL: Source Code, https://github.com/DeepPythonist/marzbanapilib
Keywords: marzban,vpn,api,client,async
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Framework :: AsyncIO
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.24.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: aiofiles>=23.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: isort>=5.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Dynamic: license-file

# MarzbanAPILib

A modern, async Python client library for interacting with [Marzban VPN panel](https://github.com/Gozargah/Marzban) API.

## Features

- 🚀 **Async/await support** - Built with modern Python async patterns
- 📦 **Modular design** - Organized into logical sections for better maintainability  
- 🔐 **Type hints** - Full type annotation for better IDE support
- ⚡ **Simple & intuitive** - Easy to use API interface
- 🛡️ **Error handling** - Comprehensive error handling with meaningful messages
- 📚 **Well documented** - Detailed documentation for all methods

## Installation

Install using pip:

```bash
pip install marzbanapilib
```

## Quick Start

### Authentication with Username/Password

```python
import asyncio
from marzbanapilib import MarzbanAPI

async def main():
    # Create API client using username and password
    async with MarzbanAPI(
        base_url="http://127.0.0.1:8000",
        username="admin", 
        password="password"
    ) as api:
        # Get system statistics
        stats = await api.system.get_stats()
        print(f"Total users: {stats['total_user']}")
        
        # Create a new user
        user = await api.user.create_user({
            "username": "test_user",
            "proxies": {"vmess": {}, "vless": {}},
            "expire": 0,  # No expiration
            "data_limit": 0  # Unlimited
        })
        print(f"Created user: {user['username']}")

# Run the async function
asyncio.run(main())
```

### Authentication with Access Token

```python
import asyncio
from marzbanapilib import MarzbanAPI

async def main():
    # Use pre-existing access token (no username/password needed)
    async with MarzbanAPI(
        base_url="http://127.0.0.1:8000",
        access_token="your_jwt_token_here"
    ) as api:
        # Get system statistics
        stats = await api.system.get_stats()
        print(f"Total users: {stats['total_user']}")

asyncio.run(main())
```

## Architecture

The library is organized into modular sections:

- **`user`** - User management operations
- **`admin`** - Admin management operations  
- **`system`** - System statistics and configuration
- **`core`** - Xray core management
- **`node`** - Multi-node management

### Using Sections

```python
async with MarzbanAPI(...) as api:
    # User operations
    await api.user.create_user(...)
    await api.user.get_users()
    await api.user.reset_data_usage("username")
    
    # System operations
    await api.system.get_stats()
    await api.system.get_inbounds()
    
    # Core operations
    await api.core.restart()
    await api.core.get_config()
    
    # Node operations
    await api.node.get_all()
    await api.node.create(...)
```

## Advanced Usage

### Manual Authentication

```python
# With username/password
api = MarzbanAPI("http://127.0.0.1:8000", "admin", "password")
await api.authenticate()

# Or with access token
api = MarzbanAPI("http://127.0.0.1:8000", access_token="your_jwt_token")
await api.authenticate()

# Use the API
users = await api.user.get_users()

# Don't forget to close
await api.close()
```

### Error Handling

```python
from marzbanapilib import MarzbanAPI

async with MarzbanAPI(...) as api:
    try:
        user = await api.user.get_user("nonexistent")
    except ValueError as e:
        print(f"User not found: {e}")
    except httpx.HTTPStatusError as e:
        print(f"HTTP error: {e}")
```

### Filtering Users

```python
# Get active users with pagination
users = await api.user.get_users(
    offset=0,
    limit=50,
    status="active",
    sort="created_at"
)
```

## API Reference

### User Management
- `create_user(data)` - Create new user
- `get_user(username)` - Get user details
- `modify_user(username, data)` - Modify user
- `delete_user(username)` - Delete user
- `get_users(**filters)` - List users with filters
- `reset_data_usage(username)` - Reset user data usage
- `revoke_subscription(username)` - Revoke user subscription
- `get_usage(username)` - Get user usage statistics
- And more...

### System Management
- `get_stats()` - Get system statistics
- `get_inbounds()` - Get inbound configurations
- `get_hosts()` - Get proxy hosts
- `modify_hosts(data)` - Modify proxy hosts

### Core Management
- `get_stats()` - Get core statistics
- `restart()` - Restart Xray core
- `get_config()` - Get core configuration
- `modify_config(data)` - Modify core configuration

### Node Management
- `get_all()` - List all nodes
- `create(data)` - Create new node
- `get(node_id)` - Get node details
- `modify(node_id, data)` - Modify node
- `delete(node_id)` - Delete node
- `reconnect(node_id)` - Reconnect node
- `get_usage()` - Get nodes usage statistics

## Requirements

- Python 3.7+
- httpx
- pydantic
- aiofiles

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

For issues and feature requests, please use the [GitHub issue tracker](https://github.com/DeepPythonist/marzbanapilib/issues). 
