pasarguard 2.2.0__tar.gz → 2.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. pasarguard-2.2.2/.github/workflows/api-governance.yml +119 -0
  2. pasarguard-2.2.2/CNAME +1 -0
  3. {pasarguard-2.2.0 → pasarguard-2.2.2}/PKG-INFO +33 -11
  4. {pasarguard-2.2.0 → pasarguard-2.2.2}/README.fa.md +37 -8
  5. {pasarguard-2.2.0 → pasarguard-2.2.2}/README.md +29 -8
  6. pasarguard-2.2.2/docs/CNAME +1 -0
  7. pasarguard-2.2.2/docs/index.html +645 -0
  8. pasarguard-2.2.2/docs/openapi.json +1 -0
  9. pasarguard-2.2.2/examples/README.md +73 -0
  10. pasarguard-2.2.2/examples/admin_roles.py +46 -0
  11. pasarguard-2.2.2/examples/admins.py +87 -0
  12. pasarguard-2.2.2/examples/authentication.py +53 -0
  13. pasarguard-2.2.2/examples/client_templates.py +52 -0
  14. pasarguard-2.2.2/examples/cores.py +53 -0
  15. pasarguard-2.2.2/examples/getting_started.py +57 -0
  16. pasarguard-2.2.2/examples/groups.py +70 -0
  17. pasarguard-2.2.2/examples/health.py +31 -0
  18. pasarguard-2.2.2/examples/hosts.py +50 -0
  19. pasarguard-2.2.2/examples/legacy_aliases.py +89 -0
  20. pasarguard-2.2.2/examples/nodes.py +105 -0
  21. pasarguard-2.2.2/examples/settings.py +40 -0
  22. pasarguard-2.2.2/examples/setup.py +49 -0
  23. pasarguard-2.2.2/examples/subscriptions.py +96 -0
  24. pasarguard-2.2.2/examples/system.py +42 -0
  25. pasarguard-2.2.2/examples/tools.py +69 -0
  26. pasarguard-2.2.2/examples/user_hwid.py +51 -0
  27. pasarguard-2.2.2/examples/user_templates.py +53 -0
  28. pasarguard-2.2.2/examples/users.py +193 -0
  29. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/__init__.py +12 -3
  30. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/_imports.py +4 -3
  31. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/base.py +16 -5
  32. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/system.py +16 -0
  33. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/user.py +5 -0
  34. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/general.py +7 -1
  35. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/_base.py +3 -1
  36. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/admin_role.py +13 -9
  37. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/settings.py +12 -1
  38. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/system.py +23 -0
  39. pasarguard-2.2.2/pasarguard/utils.py +163 -0
  40. {pasarguard-2.2.0 → pasarguard-2.2.2}/pyproject.toml +6 -2
  41. {pasarguard-2.2.0 → pasarguard-2.2.2}/uv.lock +9 -4
  42. pasarguard-2.2.0/openapi.json +0 -1
  43. pasarguard-2.2.0/pasarguard/utils.py +0 -30
  44. {pasarguard-2.2.0 → pasarguard-2.2.2}/.gitattributes +0 -0
  45. {pasarguard-2.2.0 → pasarguard-2.2.2}/.github/dependabot.yml +0 -0
  46. {pasarguard-2.2.0 → pasarguard-2.2.2}/.github/workflows/publish-pypi.yml +0 -0
  47. {pasarguard-2.2.0 → pasarguard-2.2.2}/.gitignore +0 -0
  48. {pasarguard-2.2.0 → pasarguard-2.2.2}/LICENSE +0 -0
  49. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/api.py +0 -0
  50. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/__init__.py +0 -0
  51. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/admin.py +0 -0
  52. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/admin_role.py +0 -0
  53. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/client_template.py +0 -0
  54. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/compat.py +0 -0
  55. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/core.py +0 -0
  56. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/default.py +0 -0
  57. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/groups.py +0 -0
  58. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/host.py +0 -0
  59. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/node.py +0 -0
  60. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/settings.py +0 -0
  61. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/setup.py +0 -0
  62. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/subscription.py +0 -0
  63. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/user_hwid.py +0 -0
  64. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/client/user_template.py +0 -0
  65. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/__init__.py +0 -0
  66. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/admin.py +0 -0
  67. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/client_template.py +0 -0
  68. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/core.py +0 -0
  69. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/node.py +0 -0
  70. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/proxy.py +0 -0
  71. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/enums/user.py +0 -0
  72. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/__init__.py +0 -0
  73. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/admin.py +0 -0
  74. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/client_template.py +0 -0
  75. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/common.py +0 -0
  76. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/core.py +0 -0
  77. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/groups.py +0 -0
  78. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/host.py +0 -0
  79. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/node.py +0 -0
  80. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/proxy.py +0 -0
  81. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/subscription.py +0 -0
  82. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/user.py +0 -0
  83. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/user_hwid.py +0 -0
  84. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard/models/user_template.py +0 -0
  85. {pasarguard-2.2.0 → pasarguard-2.2.2}/pasarguard-sdk.code-workspace +0 -0
@@ -0,0 +1,119 @@
1
+ name: API Governance
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, ready_for_review]
6
+ paths:
7
+ - docs/openapi.json
8
+ - .github/workflows/api-governance.yml
9
+ workflow_dispatch:
10
+ inputs:
11
+ base_ref:
12
+ description: Base branch or ref to compare against
13
+ required: false
14
+ default: main
15
+ head_ref:
16
+ description: Head branch or ref to compare
17
+ required: false
18
+ default: ""
19
+
20
+ jobs:
21
+ delimit:
22
+ name: Delimit CLI OpenAPI diff
23
+ runs-on: ubuntu-latest
24
+ permissions:
25
+ contents: read
26
+ pull-requests: write
27
+ steps:
28
+ - name: Checkout repository
29
+ uses: actions/checkout@v4
30
+ with:
31
+ ref: ${{ github.event_name == 'workflow_dispatch' && inputs.head_ref || github.ref }}
32
+ fetch-depth: 0
33
+
34
+ - name: Checkout base revision
35
+ uses: actions/checkout@v4
36
+ with:
37
+ ref: ${{ github.event_name == 'workflow_dispatch' && inputs.base_ref || github.event.pull_request.base.sha }}
38
+ path: base
39
+ fetch-depth: 1
40
+
41
+ - name: Compare OpenAPI contract
42
+ shell: bash
43
+ run: |
44
+ set -euo pipefail
45
+
46
+ npx --yes delimit-cli@4.9.0 diff base/docs/openapi.json docs/openapi.json --json > delimit-report.json
47
+ npx --yes delimit-cli@4.9.0 diff base/docs/openapi.json docs/openapi.json > delimit-diff.txt
48
+
49
+ node <<'NODE'
50
+ const fs = require('fs');
51
+
52
+ const report = JSON.parse(fs.readFileSync('delimit-report.json', 'utf8'));
53
+ const changes = report.changes || [];
54
+ const breaking = changes.filter((change) => change.is_breaking);
55
+ const nonBreaking = changes.filter((change) => !change.is_breaking);
56
+ const semver = breaking.length > 0 ? 'MAJOR' : changes.length > 0 ? 'MINOR' : 'NONE';
57
+
58
+ let body = '<!-- delimit-cli-openapi-diff -->\n';
59
+ body += '## API Contract Diff\n\n';
60
+ body += `Delimit compared \`docs/openapi.json\` against the base branch and found **${changes.length} change(s)**.\n\n`;
61
+ body += `| Result | Count |\n`;
62
+ body += `| --- | ---: |\n`;
63
+ body += `| Breaking changes | **${breaking.length}** |\n`;
64
+ body += `| Non-breaking changes | **${nonBreaking.length}** |\n`;
65
+ body += `| Recommended semver | **${semver}** |\n\n`;
66
+
67
+ if (breaking.length > 0) {
68
+ body += '### Breaking Changes\n\n';
69
+ body += 'These changes may require client updates before release.\n\n';
70
+ breaking.forEach((change, index) => {
71
+ body += `${index + 1}. **${change.type.replace(/_/g, ' ')}** at \`${change.path}\`\n`;
72
+ body += ` ${change.message}\n`;
73
+ });
74
+ body += '\n';
75
+ } else {
76
+ body += '### Breaking Changes\n\n';
77
+ body += 'No breaking API changes detected.\n\n';
78
+ }
79
+
80
+ if (nonBreaking.length > 0) {
81
+ body += '<details open>\n<summary>Non-breaking changes (' + nonBreaking.length + ')</summary>\n\n';
82
+ nonBreaking.forEach((change) => {
83
+ body += `- **${change.type.replace(/_/g, ' ')}** at \`${change.path}\` - ${change.message}\n`;
84
+ });
85
+ body += '\n</details>\n\n';
86
+ }
87
+
88
+ body += '<details>\n<summary>Raw Delimit CLI output</summary>\n\n';
89
+ body += '```text\n';
90
+ body += fs.readFileSync('delimit-diff.txt', 'utf8').trim();
91
+ body += '\n```\n\n</details>\n\n';
92
+ body += '> Advisory mode: this workflow reports API changes but does not block the PR.\n';
93
+
94
+ fs.writeFileSync('delimit-comment.md', body);
95
+ fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, body.replace('<!-- delimit-cli-openapi-diff -->\n', ''));
96
+ NODE
97
+
98
+ - name: Comment on PR
99
+ if: github.event_name == 'pull_request'
100
+ env:
101
+ GH_TOKEN: ${{ github.token }}
102
+ PR_NUMBER: ${{ github.event.pull_request.number }}
103
+ shell: bash
104
+ run: |
105
+ set -euo pipefail
106
+
107
+ comment_id="$(
108
+ gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
109
+ --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | contains("<!-- delimit-cli-openapi-diff -->"))) | .id' \
110
+ | head -n 1
111
+ )"
112
+
113
+ if [ -n "$comment_id" ]; then
114
+ gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" \
115
+ -f body="$(cat delimit-comment.md)" >/dev/null
116
+ else
117
+ gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
118
+ -f body="$(cat delimit-comment.md)" >/dev/null
119
+ fi
pasarguard-2.2.2/CNAME ADDED
@@ -0,0 +1 @@
1
+ pg-api.ak6.ir
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pasarguard
3
- Version: 2.2.0
3
+ Version: 2.2.2
4
4
  Summary: A modern async Python client for the Pasarguard API with typed models and full admin automation support
5
5
  Project-URL: Homepage, https://github.com/AmirKenzo/pasarguard_api
6
6
  Project-URL: Repository, https://github.com/AmirKenzo/pasarguard_api
@@ -26,9 +26,10 @@ Classifier: Typing :: Typed
26
26
  Requires-Python: <3.15,>=3.10
27
27
  Requires-Dist: datetime>=5.5
28
28
  Requires-Dist: httpx>=0.28.1
29
- Requires-Dist: paramiko>=4.0.0
30
29
  Requires-Dist: pydantic<2.14,>=2.4.1
31
- Requires-Dist: sshtunnel>=0.4.0
30
+ Provides-Extra: ssh
31
+ Requires-Dist: paramiko>=4.0.0; extra == 'ssh'
32
+ Requires-Dist: sshtunnel>=0.4.0; extra == 'ssh'
32
33
  Description-Content-Type: text/markdown
33
34
 
34
35
  # Pasarguard
@@ -39,7 +40,7 @@ Description-Content-Type: text/markdown
39
40
  ![HTTPX](https://img.shields.io/badge/HTTPX-async-06b6d4)
40
41
  ![Pydantic](https://img.shields.io/badge/Pydantic-v2-ef476f)
41
42
 
42
- **Pasarguard** is a modern, typed, async Python client for the Pasarguard API.
43
+ **Pasarguard** is a modern, typed, async Python client for the [PasarGuard Panel](https://github.com/PasarGuard/panel) API.
43
44
 
44
45
  [فارسی](README.fa.md)
45
46
 
@@ -51,6 +52,12 @@ It provides a clean interface for authentication, users, admins, nodes, groups,
51
52
  pip install pasarguard
52
53
  ```
53
54
 
55
+ Install SSH tunnel support only when needed:
56
+
57
+ ```bash
58
+ pip install "pasarguard[ssh]"
59
+ ```
60
+
54
61
  ```bash
55
62
  uv add pasarguard
56
63
  ```
@@ -60,7 +67,7 @@ uv add pasarguard
60
67
  - Async-first API client.
61
68
  - Typed request and response models with Pydantic v2.
62
69
  - Bearer-token authentication.
63
- - Optional SSH tunnel support.
70
+ - Optional SSH tunnel support via the `ssh` extra.
64
71
  - User, admin, node, group, host, core, template, and subscription management.
65
72
  - Bulk operations for users, admins, nodes, groups, hosts, and templates.
66
73
  - Usage metrics, realtime node stats, inbound details, and worker health endpoints.
@@ -78,7 +85,7 @@ uv add pasarguard
78
85
  import asyncio
79
86
  import os
80
87
 
81
- from pasarguard import PasarguardAPI, UserCreate, UserStatus
88
+ from pasarguard import PasarguardAPI, Tools, UserCreate, UserStatus
82
89
 
83
90
 
84
91
  async def main() -> None:
@@ -92,13 +99,12 @@ async def main() -> None:
92
99
  password=os.environ["PASARGUARD_ADMIN_PASSWORD"],
93
100
  )
94
101
 
95
- user = await api.create_user(
102
+ user = await api.create_user_in_all_groups(
96
103
  UserCreate(
97
- username="customer-1001",
98
- data_limit=50 * 1024**3,
99
- expire=30,
104
+ username=Tools.random_username(prefix="customer"),
105
+ data_limit=Tools.gb(50),
106
+ expire=Tools.days(30),
100
107
  status=UserStatus.ACTIVE,
101
- group_ids=[1],
102
108
  note="Created by automation",
103
109
  ),
104
110
  token=token.access_token,
@@ -110,6 +116,22 @@ async def main() -> None:
110
116
  asyncio.run(main())
111
117
  ```
112
118
 
119
+ ## Convenience helpers
120
+
121
+ ```python
122
+ from pasarguard import Tools
123
+
124
+ username = Tools.random_username(prefix="trial")
125
+ traffic_limit = Tools.gb(20) # 20 GiB in bytes
126
+ expire_at = Tools.days(30) # Unix timestamp for 30 days from now
127
+
128
+ assert Tools.to_bytes("500MB") == 500 * 1024**2
129
+ assert Tools.to_timestamp("12h") > 0
130
+ ```
131
+
132
+ Supported size helpers: `Tools.mb()`, `Tools.gb()`, `Tools.tb()`.
133
+ Supported timestamp helpers: `Tools.minutes()`, `Tools.hours()`, `Tools.days()`, `Tools.to_timestamp()`.
134
+
113
135
  ## Authentication
114
136
 
115
137
  ```python
@@ -8,7 +8,7 @@
8
8
 
9
9
  <div dir="rtl">
10
10
 
11
- **Pasarguard** یک کلاینت مدرن، تایپ‌شده و غیرهمزمان برای کار با API پاسارگارد در پایتون است.
11
+ **Pasarguard** یک کلاینت مدرن، تایپ‌شده و غیرهمزمان برای کار با API [پنل PasarGuard](https://github.com/PasarGuard/panel) در پایتون است.
12
12
 
13
13
  [English](README.md)
14
14
 
@@ -20,6 +20,12 @@
20
20
  pip install pasarguard
21
21
  ```
22
22
 
23
+ برای پشتیبانی از تونل SSH فقط وقتی نیاز داری extra مربوطه را نصب کن:
24
+
25
+ ```bash
26
+ pip install "pasarguard[ssh]"
27
+ ```
28
+
23
29
  ```bash
24
30
  uv add pasarguard
25
31
  ```
@@ -29,7 +35,7 @@ uv add pasarguard
29
35
  - کلاینت کاملاً async.
30
36
  - مدل‌های تایپ‌شده برای درخواست و پاسخ با Pydantic v2.
31
37
  - احراز هویت با Bearer Token.
32
- - پشتیبانی اختیاری از تونل SSH.
38
+ - پشتیبانی اختیاری از تونل SSH با extra جداگانه‌ی `ssh`.
33
39
  - مدیریت کاربران، ادمین‌ها، نودها، گروه‌ها، هاست‌ها، coreها، قالب‌ها و اشتراک‌ها.
34
40
  - عملیات گروهی برای کاربران، ادمین‌ها، نودها، گروه‌ها، هاست‌ها و قالب‌ها.
35
41
  - دریافت آمار مصرف، وضعیت لحظه‌ای نودها، جزئیات inbound و سلامت workerها.
@@ -49,7 +55,7 @@ uv add pasarguard
49
55
  import asyncio
50
56
  import os
51
57
 
52
- from pasarguard import PasarguardAPI, UserCreate, UserStatus
58
+ from pasarguard import PasarguardAPI, Tools, UserCreate, UserStatus
53
59
 
54
60
 
55
61
  async def main() -> None:
@@ -63,13 +69,12 @@ async def main() -> None:
63
69
  password=os.environ["PASARGUARD_ADMIN_PASSWORD"],
64
70
  )
65
71
 
66
- user = await api.create_user(
72
+ user = await api.create_user_in_all_groups(
67
73
  UserCreate(
68
- username="customer-1001",
69
- data_limit=50 * 1024**3,
70
- expire=30,
74
+ username=Tools.random_username(prefix="customer"),
75
+ data_limit=Tools.gb(50),
76
+ expire=Tools.days(30),
71
77
  status=UserStatus.ACTIVE,
72
- group_ids=[1],
73
78
  note="Created by automation",
74
79
  ),
75
80
  token=token.access_token,
@@ -83,6 +88,30 @@ asyncio.run(main())
83
88
 
84
89
  <div dir="rtl">
85
90
 
91
+ ## ابزارهای کمکی
92
+
93
+ </div>
94
+
95
+ ```python
96
+ from pasarguard import Tools
97
+
98
+ username = Tools.random_username(prefix="trial")
99
+ traffic_limit = Tools.gb(20) # 20 GiB in bytes
100
+ expire_at = Tools.days(30) # Unix timestamp for 30 days from now
101
+
102
+ assert Tools.to_bytes("500MB") == 500 * 1024**2
103
+ assert Tools.to_timestamp("12h") > 0
104
+ ```
105
+
106
+ <div dir="rtl">
107
+
108
+ ابزارهای حجم پشتیبانی‌شده: `Tools.mb()`، `Tools.gb()` و `Tools.tb()`.
109
+ ابزارهای زمان، timestamp آینده برمی‌گردانند: `Tools.minutes()`، `Tools.hours()`، `Tools.days()` و `Tools.to_timestamp()`.
110
+
111
+ </div>
112
+
113
+ <div dir="rtl">
114
+
86
115
  ## احراز هویت
87
116
 
88
117
  </div>
@@ -6,7 +6,7 @@
6
6
  ![HTTPX](https://img.shields.io/badge/HTTPX-async-06b6d4)
7
7
  ![Pydantic](https://img.shields.io/badge/Pydantic-v2-ef476f)
8
8
 
9
- **Pasarguard** is a modern, typed, async Python client for the Pasarguard API.
9
+ **Pasarguard** is a modern, typed, async Python client for the [PasarGuard Panel](https://github.com/PasarGuard/panel) API.
10
10
 
11
11
  [فارسی](README.fa.md)
12
12
 
@@ -18,6 +18,12 @@ It provides a clean interface for authentication, users, admins, nodes, groups,
18
18
  pip install pasarguard
19
19
  ```
20
20
 
21
+ Install SSH tunnel support only when needed:
22
+
23
+ ```bash
24
+ pip install "pasarguard[ssh]"
25
+ ```
26
+
21
27
  ```bash
22
28
  uv add pasarguard
23
29
  ```
@@ -27,7 +33,7 @@ uv add pasarguard
27
33
  - Async-first API client.
28
34
  - Typed request and response models with Pydantic v2.
29
35
  - Bearer-token authentication.
30
- - Optional SSH tunnel support.
36
+ - Optional SSH tunnel support via the `ssh` extra.
31
37
  - User, admin, node, group, host, core, template, and subscription management.
32
38
  - Bulk operations for users, admins, nodes, groups, hosts, and templates.
33
39
  - Usage metrics, realtime node stats, inbound details, and worker health endpoints.
@@ -45,7 +51,7 @@ uv add pasarguard
45
51
  import asyncio
46
52
  import os
47
53
 
48
- from pasarguard import PasarguardAPI, UserCreate, UserStatus
54
+ from pasarguard import PasarguardAPI, Tools, UserCreate, UserStatus
49
55
 
50
56
 
51
57
  async def main() -> None:
@@ -59,13 +65,12 @@ async def main() -> None:
59
65
  password=os.environ["PASARGUARD_ADMIN_PASSWORD"],
60
66
  )
61
67
 
62
- user = await api.create_user(
68
+ user = await api.create_user_in_all_groups(
63
69
  UserCreate(
64
- username="customer-1001",
65
- data_limit=50 * 1024**3,
66
- expire=30,
70
+ username=Tools.random_username(prefix="customer"),
71
+ data_limit=Tools.gb(50),
72
+ expire=Tools.days(30),
67
73
  status=UserStatus.ACTIVE,
68
- group_ids=[1],
69
74
  note="Created by automation",
70
75
  ),
71
76
  token=token.access_token,
@@ -77,6 +82,22 @@ async def main() -> None:
77
82
  asyncio.run(main())
78
83
  ```
79
84
 
85
+ ## Convenience helpers
86
+
87
+ ```python
88
+ from pasarguard import Tools
89
+
90
+ username = Tools.random_username(prefix="trial")
91
+ traffic_limit = Tools.gb(20) # 20 GiB in bytes
92
+ expire_at = Tools.days(30) # Unix timestamp for 30 days from now
93
+
94
+ assert Tools.to_bytes("500MB") == 500 * 1024**2
95
+ assert Tools.to_timestamp("12h") > 0
96
+ ```
97
+
98
+ Supported size helpers: `Tools.mb()`, `Tools.gb()`, `Tools.tb()`.
99
+ Supported timestamp helpers: `Tools.minutes()`, `Tools.hours()`, `Tools.days()`, `Tools.to_timestamp()`.
100
+
80
101
  ## Authentication
81
102
 
82
103
  ```python
@@ -0,0 +1 @@
1
+ pg-api.ak6.ir