Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #10

Merged
merged 7 commits into from
Apr 14, 2024
Merged

Dev #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install aiohttp
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
1 change: 1 addition & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install build
pip install aiohttp
- name: Build package
run: python -m build
- name: Publish package
Expand Down
88 changes: 45 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ A Python library that helps you easily use [Marzban](https://github.com/Gozargah
```shell
pip install marzpy
```
requirements : ```requests```
requirements : ```aiohttp```
# How To Use
```python
from marzpy import Marzban
import asyncio

async def main():
panel = Marzban("username","password","https://example.com")
token = await await panel.get_token()
#await await panel.anyfunction(token)

panel = Marzban("username","password","https://example.com")

mytoken = panel.get_token()

# panel.anyfunction()
asyncio.run(main())

```
# Features
Expand Down Expand Up @@ -76,64 +78,64 @@ from marzpy import Marzban

panel = Marzban("username","password","https://example.com")

mytoken = panel.get_token()
mytoken = await panel.get_token()

```
### Get Current admin
```python
admin = panel.get_current_admin(token=mytoken)
admin = await panel.get_current_admin(token=mytoken)
print(admin) #output: {'username': 'admin', 'is_sudo': True}
```
### Create Admin
```python
info = {'username':'test','password':'pasword','is_sudo':False}
rsault = panel.create_admin(token=mytoken,data=info)
rsault = await panel.create_admin(token=mytoken,data=info)
print(result) #output: success
```
### Modify Admin
```python
target_admin = "test"
info = {'password':'newpassword','is_sudo':False}
result = panel.change_admin_password(username=target_admin,token=mytoken,data=info)
result = await panel.change_admin_password(username=target_admin,token=mytoken,data=info)
print(result) #output: success
```
### Remove Admin
```python
target_admin = "test"
result = panel.delete_admin(username=target_admin,token=mytoken)
result = await panel.delete_admin(username=target_admin,token=mytoken)
print(result) #output: success
```
### Get All Admins
```python
result = panel.get_all_admins(token=mytoken)
result = await panel.get_all_admins(token=mytoken)
print(result)
#output: [{'username': 'test', 'is_sudo': True}, {'username': 'test1', 'is_sudo': False}]
```
### User Subscription
```python
subscription_url = "https://sub.yourdomain.com/sub/eyJhbGciOiJIUzI8NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJNbWRDcmFaeSIsImFjY2VzcyI8InN1YnNjcmlwdGlvbiIsImlhdCI1MTY5NDk1NTkxMH0.o75ML5835SPXpVPKXcvEIUxMTwSy-4XGS9NIdWOAmXY"
result = panel.get_subscription(subscription_url)
result = await panel.get_subscription(subscription_url)
print(result) #output: Configs
```
### User Subscription info
```python
subscription_url = "https://sub.yourdomain.com/sub/eyJhbGciOiJIUzI8NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJNbWRDcmFaeSIsImFjY2VzcyI8InN1YnNjcmlwdGlvbiIsImlhdCI1MTY5NDk1NTkxMH0.o75ML5835SPXpVPKXcvEIUxMTwSy-4XGS9NIdWOAmXY"
result = panel.get_subscription_info(subscription_url)
result = await panel.get_subscription_info(subscription_url)
print(result) #output: User information (usage,links,inbounds,....)
```
### Get System Stats
```python
result = panel.get_system_stats(token=mytoken)
result = await panel.get_system_stats(token=mytoken)
print(result) #output: system stats Memory & CPU usage ...
```
### Get Inbounds
```python
result = panel.get_inbounds(token=mytoken)
result = await panel.get_inbounds(token=mytoken)
print(result) #output: list of inbounds
```
### Get Hosts
```python
result = panel.get_hosts(token=mytoken)
result = await panel.get_hosts(token=mytoken)
print(result) #output: list of hosts
```
### Modify Hosts
Expand All @@ -153,30 +155,30 @@ hosts = {
]
}
# **Backup first**
result = panel.modify_hosts(token=mytoken,data=hosts)
result = await panel.modify_hosts(token=mytoken,data=hosts)
print(result) #output: hosts
```
### Get Core Stats
```python
result = panel.get_xray_core(token=mytoken)
result = await panel.get_xray_core(token=mytoken)
print(result)
#output: {'version': '1.8.1', 'started': True, 'logs_websocket': '/api/core/logs'}
```
### Restart Core
```python
result = panel.restart_xray_core(token=mytoken)
result = await panel.restart_xray_core(token=mytoken)
print(result)
#output: success
```
### Get Core Config
```python
result = panel.get_xray_config(token=mytoken)
result = await panel.get_xray_config(token=mytoken)
print(result) #output: your xray core config
```
### Modify Core Config
```python
new_config={"your config"}
result = panel.modify_xray_config(token=mytoken,config=new_config)
result = await panel.modify_xray_config(token=mytoken,config=new_config)
print(result) #output: success
```
### Add User
Expand All @@ -194,13 +196,13 @@ user = User(
data_limit=0,
data_limit_reset_strategy="no_reset",
)
result = panel.add_user(user=user, token=token) #return new User object
result = await panel.add_user(user=user, token=token) #return new User object

print(result.username) #-> Mewhrzad, #user.proxies, #user.inbounds, #user.expire, #user.data_limit, #userdata_limit_reset_strategy, #user.status, #user.used_traffic, #user.lifetime_used_traffic, #user.created_at, #user.links, #user.subscription_url, #user.excluded_inbounds
```
### Get User
```python
result = panel.get_user("Mewhrzad",token=mytoken) #return User object
result = await panel.get_user("Mewhrzad",token=mytoken) #return User object
print(result.subscription_url)
```
### Modify User
Expand All @@ -217,40 +219,40 @@ new_user = User(
data_limit_reset_strategy="no_reset",
status="active",
)
result = panel.modify_user("Mewhrzad", token=mytoken, user=new_user)
result = await panel.modify_user("Mewhrzad", token=mytoken, user=new_user)
print(result.subscription_url) #output: modified user object
```
### Remove User
```python
result = panel.delete_user("test", token=mytoken)
result = await panel.delete_user("test", token=mytoken)
print(result) #output: success
```
### Reset User Data Usage
```python
result = panel.reset_user_traffic("test", token=mytoken)
result = await panel.reset_user_traffic("test", token=mytoken)
print(result) #output: success
```
### Reset All Users Data Usage
```python
result = panel.reset_all_users_traffic(token=mytoken)
result = await panel.reset_all_users_traffic(token=mytoken)
print(result) #output: success
```
### Get All Users
```python
result = panel.get_all_users(token=mytoken) #return list of users
result = await panel.get_all_users(token=mytoken) #return list of users
for user in result:
print(user.username)
```
### Get User Usage
```python
result = panel.get_user_usage("mewhrzad",token=mytoken)
result = await panel.get_user_usage("mewhrzad",token=mytoken)
print(result)
#output: [{'node_id': None, 'node_name': 'MTN', 'used_traffic': 0},
#{'node_id': 1, 'node_name': 'MCI', 'used_traffic': 0}]
```
### Get All User Templates
```python
result = panel.get_all_templates(token=mytoken) #return template list object
result = await panel.get_all_templates(token=mytoken) #return template list object
for template in result:
print(template.name)
```
Expand All @@ -266,13 +268,13 @@ temp = Template(
username_prefix=None,
username_suffix=None,
)
result = panel.add_template(token=mytoken, template=temp) # return new Template object
result = await panel.add_template(token=mytoken, template=temp) # return new Template object
print(result.name) #output: new_template
```
### Get User Template
```python
template_id = 11
result = panel.get_template_by_id(token=mytoken, id=template_id) # return Template object
result = await panel.get_template_by_id(token=mytoken, id=template_id) # return Template object
print(result.name) #output: new_template
```
### Modify User Template
Expand All @@ -287,13 +289,13 @@ temp = Template(
username_prefix=None,
username_suffix=None,
)
result = panel.modify_template_by_id(
result = await panel.modify_template_by_id(
id=1, token=mytoken, template=temp) # return Modified Template object
print(result.name) #output: new_template2
```
### Remove User Template
```python
result = panel.delete_template_by_id(id=1, token=mytoken)
result = await panel.delete_template_by_id(id=1, token=mytoken)
print(result) #output: success
```
### Add Node
Expand All @@ -312,12 +314,12 @@ my_node = Node(
message="string",
)

result = panel.add_node(token=mytoken, node=my_node) # return new Node object
result = await panel.add_node(token=mytoken, node=my_node) # return new Node object
print(result.address)
```
### Get Node
```python
result = panel.get_node_by_id(id=1, token=mytoken) # return exist Node object
result = await panel.get_node_by_id(id=1, token=mytoken) # return exist Node object
print(result.address) #output: address of node 1
```
### Modify Node
Expand All @@ -336,30 +338,30 @@ my_node = Node(
message="string",
)

result = panel.modify_node_by_id(id=1, token=mytoken,node=my_node) # return modified Node object
result = await panel.modify_node_by_id(id=1, token=mytoken,node=my_node) # return modified Node object
print(result.address) #output:test.example.com
```
### Remove Node
```python
result = panel.delete_node(id=1, token=mytoken)
result = await panel.delete_node(id=1, token=mytoken)
print(result) #output: success
```
### Get All Nodes
```python
result = panel.get_all_nodes(token=mytoken) # return List of Node object
result = await panel.get_all_nodes(token=mytoken) # return List of Node object
for node in result:
print(node.address)
```
### Reconenct Node
```python
result = panel.reconnect_node(id=1,token=mytoken)
result = await panel.reconnect_node(id=1,token=mytoken)
print(result) #output: success
```
### Get Node Usage
```python
result = panel.get_nodes_usage(token=mytoken)
result = await panel.get_nodes_usage(token=mytoken)
for node in result:
print(node)
#output:{'node_id': 1, 'node_name': 'N1', 'uplink': 1000000000000, 'downlink': 1000000000000}
# {'node_id': 2, 'node_name': 'N2', 'uplink': 1000000000000, 'downlink': 1000000000000}
```
```
Loading
Loading