calagoapi 1.0.dev1__tar.gz → 1.0.dev3__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 (90) hide show
  1. {calagoapi-1.0.dev1/src/calagoapi.egg-info → calagoapi-1.0.dev3}/PKG-INFO +23 -3
  2. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/README.md +252 -232
  3. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/pyproject.toml +2 -1
  4. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/__init__.py +195 -190
  5. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/account/__init__.py +14 -14
  6. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/account/account.py +292 -292
  7. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/account/auth.py +72 -72
  8. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/account/models.py +221 -221
  9. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/admin/__init__.py +48 -48
  10. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/admin/admin.py +350 -341
  11. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/admin/managers.py +490 -490
  12. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/admin/resources.py +970 -970
  13. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/aio/__init__.py +9 -9
  14. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/aio/console.py +289 -289
  15. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/aio/panel.py +193 -176
  16. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/__init__.py +63 -63
  17. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/account.py +195 -195
  18. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/admin.py +402 -402
  19. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/attachments.py +27 -27
  20. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/auth.py +52 -52
  21. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/backups.py +99 -99
  22. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/client.py +198 -198
  23. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/databases.py +217 -217
  24. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/files.py +210 -210
  25. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/network.py +84 -84
  26. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/public.py +13 -13
  27. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/schedules.py +79 -79
  28. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/servers.py +114 -114
  29. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/users.py +27 -27
  30. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/api/versions.py +32 -29
  31. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/backups/__init__.py +8 -8
  32. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/backups/backup.py +292 -292
  33. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/backups/manager.py +177 -177
  34. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/console/__init__.py +6 -6
  35. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/console/console.py +392 -392
  36. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/databases/__init__.py +12 -12
  37. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/databases/database.py +445 -445
  38. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/databases/explorer.py +159 -159
  39. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/databases/manager.py +122 -122
  40. calagoapi-1.0.dev3/src/calagoapi/extensions/__init__.py +145 -0
  41. calagoapi-1.0.dev3/src/calagoapi/extensions/base.py +232 -0
  42. calagoapi-1.0.dev3/src/calagoapi/extensions/compat.py +50 -0
  43. calagoapi-1.0.dev3/src/calagoapi/extensions/discovery.py +35 -0
  44. calagoapi-1.0.dev3/src/calagoapi/extensions/exceptions.py +80 -0
  45. calagoapi-1.0.dev3/src/calagoapi/extensions/members.py +298 -0
  46. calagoapi-1.0.dev3/src/calagoapi/extensions/registry.py +739 -0
  47. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/files/__init__.py +9 -9
  48. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/files/file.py +196 -196
  49. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/files/manager.py +437 -437
  50. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/network/__init__.py +8 -8
  51. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/network/allocation.py +99 -99
  52. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/network/manager.py +132 -132
  53. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/nodes/__init__.py +6 -6
  54. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/nodes/node.py +477 -477
  55. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/panel.py +162 -162
  56. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/schedules/__init__.py +14 -14
  57. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/schedules/builders.py +461 -461
  58. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/schedules/manager.py +107 -107
  59. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/schedules/schedule.py +214 -214
  60. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/servers/__init__.py +13 -13
  61. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/servers/admin.py +430 -430
  62. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/servers/generic.py +785 -785
  63. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/servers/manager.py +167 -167
  64. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/servers/minecraft.py +204 -207
  65. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/tunnels/__init__.py +5 -5
  66. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/tunnels/tunnel.py +112 -112
  67. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/users/__init__.py +11 -11
  68. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/users/activity.py +45 -45
  69. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/users/subuser.py +127 -127
  70. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/users/user.py +267 -267
  71. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/__init__.py +43 -43
  72. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/convert.py +113 -113
  73. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/exceptions.py +72 -72
  74. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/model.py +142 -142
  75. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/resource.py +100 -100
  76. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi/utils/time.py +68 -68
  77. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3/src/calagoapi.egg-info}/PKG-INFO +23 -3
  78. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi.egg-info/SOURCES.txt +9 -0
  79. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/tests/test_console.py +155 -155
  80. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/tests/test_contract.py +47 -47
  81. calagoapi-1.0.dev3/tests/test_examples.py +45 -0
  82. calagoapi-1.0.dev3/tests/test_extensions.py +879 -0
  83. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/tests/test_resilience.py +125 -125
  84. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/tests/test_scenarios.py +9 -9
  85. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/tests/test_units.py +74 -50
  86. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/LICENSE +0 -0
  87. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/setup.cfg +0 -0
  88. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi.egg-info/dependency_links.txt +0 -0
  89. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi.egg-info/requires.txt +0 -0
  90. {calagoapi-1.0.dev1 → calagoapi-1.0.dev3}/src/calagoapi.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: calagoapi
3
- Version: 1.0.dev1
3
+ Version: 1.0.dev3
4
4
  Summary: The Python SDK for Calagopus: servers, live console, files, backups, databases, schedules, nodes and full panel administration, sync and async.
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -83,7 +83,8 @@ CalagoAPI needs Python 3.9+ and depends on `requests` and `websockets`.
83
83
  | **Schedules** | Triggers (cron, crash, console line, resource usage, ...), conditions, 30+ step actions, import/export, live status, with builder helpers |
84
84
  | **Network** | Allocations, subdomains, per-server firewall, tunnels between servers |
85
85
  | **Subusers** | Invite, permissions, ignored files |
86
- | **Minecraft** | Version changer (install any Paper/Purpur/Fabric/... build), `server.properties` editing, EULA, console helpers |
86
+ | **Minecraft** | `server.properties` editing, EULA, console helpers; version changer and HungerBridge through [extensions](docs/learning/first_party_extensions.md) |
87
+ | **Extensions** | Add methods, properties and services to CalagoAPI from separate packages: `enable('version_changer')` ([guide](docs/learning/extensions.md)) |
87
88
  | **Account** | Profile, password, email, two-factor, API keys, SSH keys, passkeys, sessions, OAuth links, command snippets, activity |
88
89
  | **Admin** | Users, servers (create, deploy, transfer, suspend, limits), nodes, allocations, locations, nests and eggs, egg repositories, mounts, devices, roles, announcements, OAuth providers, database hosts, backup configurations and policies, settings, email templates, extensions, system health and updates |
89
90
  | **Async** | `AsyncPanel`: the whole API with `await`, plus a native asyncio live console |
@@ -199,11 +200,30 @@ server = panel.servers.getMinecraftServer('abc123')
199
200
 
200
201
  server.say('Server update in 5 minutes!')
201
202
  server.setProperties({'max-players': 100, 'motd': 'Welcome!'})
203
+ ```
204
+
205
+ ### Extensions
206
+
207
+ Optional features ship as separate packages and are switched on with `enable()`:
208
+
209
+ ```bash
210
+ pip install calagoapi-version-changer calagoapi-hungerbridge
211
+ ```
212
+
213
+ ```python
214
+ from calagoapi.extensions import enable
202
215
 
203
- latest = server.getBuilds('PAPER', '1.21.1', page=1, per_page=1)[0]
216
+ enable('version_changer')
217
+ latest = server.getBuilds('PAPER', '1.21.11', page=1, per_page=1)[0]
204
218
  server.installVersion(latest)
219
+ print(server.installedVersion)
220
+
221
+ enable('hungerbridge', config={'token': 'bot:9f2c...'})
222
+ print(server.hungerbridge.players())
205
223
  ```
206
224
 
225
+ Write your own: [docs/learning/creating_extensions.md](docs/learning/creating_extensions.md).
226
+
207
227
  ### Administration
208
228
 
209
229
  ```python
@@ -1,232 +1,252 @@
1
- # CalagoAPI
2
-
3
- The Python SDK for [Calagopus](https://calagopus.com).
4
-
5
- CalagoAPI wraps the whole Calagopus API (servers, files, backups, databases,
6
- schedules, networking, your account, and full panel administration) in a
7
- small, hand-written API that reads like plain Python.
8
-
9
- ```python
10
- from calagoapi import Panel
11
-
12
- panel = Panel(
13
- url='https://panel.example.com',
14
- api_key='c7sp_...'
15
- )
16
-
17
- server = panel.servers.getServer('abc123')
18
- server.sendCommand('say Hello')
19
- server.restart()
20
-
21
- if server.isOnline():
22
- print(server.getStatus(), server.getRAM(), server.getUptime(formatted=True))
23
-
24
- backup = server.createBackup('before-update')
25
- ```
26
-
27
- If you have used [HungerLib](https://github.com/iFamished/HungerLib), you
28
- already know CalagoAPI. The same objects and method names
29
- (`Panel`, `GenericServer`, `MinecraftServer`, `getStatus()`, `isOnline()`,
30
- `createBackup()`, `listFiles()`, ...) work here, backed by Calagopus.
31
-
32
- ## Installation
33
-
34
- ```bash
35
- pip install calagoapi
36
- ```
37
-
38
- CalagoAPI needs Python 3.9+ and depends on `requests` and `websockets`.
39
-
40
- ## Features
41
-
42
- | Area | What you can do |
43
- | --- | --- |
44
- | **Servers** | Power actions, console commands, logs, live resources, status checks, rename, reinstall, timezone, auto-start, auto-kill, startup variables, docker image, server groups |
45
- | **Live console** | Stream console output over the daemon websocket, wait for a line, callbacks for output, status, stats and every daemon event, automatic token renewal and reconnects |
46
- | **Files** | List, read, write, upload, download, rename, move, copy (also to other servers), compress, decompress, chmod, search, pull from URL, file revisions, SQLite queries, directory sizes |
47
- | **Backups** | Create, restore, download, lock, rename, bulk delete, backup groups with retention policies, usage |
48
- | **Databases** | Hosted databases, dedicated database instances (PostgreSQL, MariaDB, MongoDB, Redis), database users and grants, import/export, a full **database explorer** (tables, columns, rows, queries) |
49
- | **Schedules** | Triggers (cron, crash, console line, resource usage, ...), conditions, 30+ step actions, import/export, live status, with builder helpers |
50
- | **Network** | Allocations, subdomains, per-server firewall, tunnels between servers |
51
- | **Subusers** | Invite, permissions, ignored files |
52
- | **Minecraft** | Version changer (install any Paper/Purpur/Fabric/... build), `server.properties` editing, EULA, console helpers |
53
- | **Account** | Profile, password, email, two-factor, API keys, SSH keys, passkeys, sessions, OAuth links, command snippets, activity |
54
- | **Admin** | Users, servers (create, deploy, transfer, suspend, limits), nodes, allocations, locations, nests and eggs, egg repositories, mounts, devices, roles, announcements, OAuth providers, database hosts, backup configurations and policies, settings, email templates, extensions, system health and updates |
55
- | **Async** | `AsyncPanel`: the whole API with `await`, plus a native asyncio live console |
56
- | **Reliability** | Automatic retries on rate limits (and on transient errors for reads), typed exceptions, automatic pagination |
57
-
58
- ## Quick tour
59
-
60
- ### Status and resources
61
-
62
- ```python
63
- status = server.getStatus() # 'running', 'offline', 'starting' or 'stopping'
64
-
65
- if server.isOnline():
66
- print(server.getCPU(), '%')
67
- print(server.getRAM(), '/', server.getRAMLimit(), 'MiB')
68
- print(server.getUptime(formatted=True)) # '3h 12m'
69
-
70
- server.isInstalled()
71
- server.isSuspended()
72
- ```
73
-
74
- Every important value has a getter *and* convenience checks, so you can
75
- inspect the exact state or just branch on it.
76
-
77
- ### Live console
78
-
79
- ```python
80
- for line in server.streamConsole():
81
- if 'joined the game' in line:
82
- print(line)
83
-
84
- with server.console as console:
85
- console.sendCommand('save-all')
86
- console.waitFor('Saved the game')
87
-
88
- server.onConsoleLine(print) # callbacks in a background thread
89
- ```
90
-
91
- ### Async
92
-
93
- ```python
94
- from calagoapi import AsyncPanel
95
-
96
- async with AsyncPanel(url='https://panel.example.com', api_key='c7sp_...') as panel:
97
- servers = await panel.servers.getServers()
98
- statuses = await asyncio.gather(*(server.getStatus() for server in servers))
99
-
100
- async for line in servers[0].streamConsole():
101
- print(line)
102
- ```
103
-
104
- ### Files
105
-
106
- ```python
107
- for file in server.files.listFiles('/plugins'):
108
- print(file.getName(), file.getSize(formatted=True))
109
-
110
- properties = server.readFile('/server.properties')
111
- server.writeFile('/eula.txt', 'eula=true')
112
- server.files.uploadFile('/plugins', 'build/MyPlugin.jar')
113
- server.files.downloadFile('/world.zip', 'world.zip')
114
- ```
115
-
116
- ### Backups
117
-
118
- ```python
119
- backup = server.createBackup('before-update')
120
- backup.waitUntilComplete()
121
-
122
- if backup.isSuccessful():
123
- print(backup.getSize(formatted=True))
124
-
125
- backup.lock()
126
- backup.restore(truncate_directory=True)
127
- ```
128
-
129
- ### Schedules
130
-
131
- ```python
132
- from calagoapi import triggers, conditions, actions
133
-
134
- server.schedules.createSchedule(
135
- 'Nightly restart',
136
- triggers=[triggers.cron('0 0 4 * * *')],
137
- condition=conditions.serverState('running'),
138
- steps=[
139
- actions.sendCommand('say Restarting in 1 minute'),
140
- actions.sleep(60_000),
141
- actions.createBackup('nightly', foreground=True),
142
- actions.sendPower('restart'),
143
- ],
144
- )
145
- ```
146
-
147
- ### Databases
148
-
149
- ```python
150
- db = server.createDatabase('stats')
151
- print(db.getConnectionString())
152
-
153
- db.explorer.createTable('players', [
154
- {'name': 'id', 'type': 'INT', 'primary_key': True, 'auto_increment': True},
155
- {'name': 'name', 'type': 'VARCHAR(32)'},
156
- ])
157
- db.explorer.insertRow('players', {'name': 'Steve'})
158
- print(db.explorer.query('SELECT COUNT(*) FROM players'))
159
- ```
160
-
161
- ### Minecraft
162
-
163
- ```python
164
- server = panel.servers.getMinecraftServer('abc123')
165
-
166
- server.say('Server update in 5 minutes!')
167
- server.setProperties({'max-players': 100, 'motd': 'Welcome!'})
168
-
169
- latest = server.getBuilds('PAPER', '1.21.1', page=1, per_page=1)[0]
170
- server.installVersion(latest)
171
- ```
172
-
173
- ### Administration
174
-
175
- ```python
176
- user = panel.admin.users.createUser('steve', 'steve@example.com')
177
-
178
- server = panel.admin.servers.deployServer(
179
- 'Steve SMP', owner=user, egg=panel.admin.nests.findEgg('Paper'),
180
- locations=[panel.admin.locations.getLocationByName('Frankfurt')],
181
- memory=4096, disk=20480,
182
- )
183
-
184
- for node in panel.admin.nodes.getNodes():
185
- print(node.getName(), node.getSystemOverview()['version'])
186
- ```
187
-
188
- ### Errors
189
-
190
- ```python
191
- from calagoapi import NotFoundError, PermissionDeniedError, CalagoAPIError
192
-
193
- try:
194
- panel.servers.getServer('missing')
195
- except NotFoundError:
196
- print('No such server')
197
- except CalagoAPIError as e:
198
- print(e.status_code, e.errors)
199
- ```
200
-
201
- ## Documentation
202
-
203
- The [docs](docs/) folder has a guide for every area:
204
-
205
- - [Getting started](docs/getting-started.md)
206
- - [Servers](docs/servers.md), [Minecraft servers](docs/minecraft.md), [Live console](docs/console.md)
207
- - [Files](docs/files.md), [Backups](docs/backups.md), [Databases](docs/databases.md)
208
- - [Schedules](docs/schedules.md)
209
- - [Network, subusers and tunnels](docs/network.md)
210
- - [Account and authentication](docs/account.md)
211
- - [Administration](docs/admin.md)
212
- - [Async](docs/async.md)
213
- - [Errors, pagination and utilities](docs/errors-and-utilities.md)
214
- - [Migrating from HungerLib](docs/migrating-from-hungerlib.md)
215
- - [Architecture](docs/architecture.md)
216
-
217
- Every public class and method also has a docstring with parameters and an
218
- example, so `help(server.files)` works from a Python shell.
219
-
220
- ## Development
221
-
222
- ```bash
223
- pip install -e .[dev]
224
- pytest
225
- ```
226
-
227
- The tests run offline against `openapi.json` and a fake daemon. See
228
- [Architecture](docs/architecture.md#tests).
229
-
230
- ## License
231
-
232
- GPL-3.0, see [LICENSE](LICENSE).
1
+ # CalagoAPI
2
+
3
+ The Python SDK for [Calagopus](https://calagopus.com).
4
+
5
+ CalagoAPI wraps the whole Calagopus API (servers, files, backups, databases,
6
+ schedules, networking, your account, and full panel administration) in a
7
+ small, hand-written API that reads like plain Python.
8
+
9
+ ```python
10
+ from calagoapi import Panel
11
+
12
+ panel = Panel(
13
+ url='https://panel.example.com',
14
+ api_key='c7sp_...'
15
+ )
16
+
17
+ server = panel.servers.getServer('abc123')
18
+ server.sendCommand('say Hello')
19
+ server.restart()
20
+
21
+ if server.isOnline():
22
+ print(server.getStatus(), server.getRAM(), server.getUptime(formatted=True))
23
+
24
+ backup = server.createBackup('before-update')
25
+ ```
26
+
27
+ If you have used [HungerLib](https://github.com/iFamished/HungerLib), you
28
+ already know CalagoAPI. The same objects and method names
29
+ (`Panel`, `GenericServer`, `MinecraftServer`, `getStatus()`, `isOnline()`,
30
+ `createBackup()`, `listFiles()`, ...) work here, backed by Calagopus.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install calagoapi
36
+ ```
37
+
38
+ CalagoAPI needs Python 3.9+ and depends on `requests` and `websockets`.
39
+
40
+ ## Features
41
+
42
+ | Area | What you can do |
43
+ | --- | --- |
44
+ | **Servers** | Power actions, console commands, logs, live resources, status checks, rename, reinstall, timezone, auto-start, auto-kill, startup variables, docker image, server groups |
45
+ | **Live console** | Stream console output over the daemon websocket, wait for a line, callbacks for output, status, stats and every daemon event, automatic token renewal and reconnects |
46
+ | **Files** | List, read, write, upload, download, rename, move, copy (also to other servers), compress, decompress, chmod, search, pull from URL, file revisions, SQLite queries, directory sizes |
47
+ | **Backups** | Create, restore, download, lock, rename, bulk delete, backup groups with retention policies, usage |
48
+ | **Databases** | Hosted databases, dedicated database instances (PostgreSQL, MariaDB, MongoDB, Redis), database users and grants, import/export, a full **database explorer** (tables, columns, rows, queries) |
49
+ | **Schedules** | Triggers (cron, crash, console line, resource usage, ...), conditions, 30+ step actions, import/export, live status, with builder helpers |
50
+ | **Network** | Allocations, subdomains, per-server firewall, tunnels between servers |
51
+ | **Subusers** | Invite, permissions, ignored files |
52
+ | **Minecraft** | `server.properties` editing, EULA, console helpers; version changer and HungerBridge through [extensions](docs/learning/first_party_extensions.md) |
53
+ | **Extensions** | Add methods, properties and services to CalagoAPI from separate packages: `enable('version_changer')` ([guide](docs/learning/extensions.md)) |
54
+ | **Account** | Profile, password, email, two-factor, API keys, SSH keys, passkeys, sessions, OAuth links, command snippets, activity |
55
+ | **Admin** | Users, servers (create, deploy, transfer, suspend, limits), nodes, allocations, locations, nests and eggs, egg repositories, mounts, devices, roles, announcements, OAuth providers, database hosts, backup configurations and policies, settings, email templates, extensions, system health and updates |
56
+ | **Async** | `AsyncPanel`: the whole API with `await`, plus a native asyncio live console |
57
+ | **Reliability** | Automatic retries on rate limits (and on transient errors for reads), typed exceptions, automatic pagination |
58
+
59
+ ## Quick tour
60
+
61
+ ### Status and resources
62
+
63
+ ```python
64
+ status = server.getStatus() # 'running', 'offline', 'starting' or 'stopping'
65
+
66
+ if server.isOnline():
67
+ print(server.getCPU(), '%')
68
+ print(server.getRAM(), '/', server.getRAMLimit(), 'MiB')
69
+ print(server.getUptime(formatted=True)) # '3h 12m'
70
+
71
+ server.isInstalled()
72
+ server.isSuspended()
73
+ ```
74
+
75
+ Every important value has a getter *and* convenience checks, so you can
76
+ inspect the exact state or just branch on it.
77
+
78
+ ### Live console
79
+
80
+ ```python
81
+ for line in server.streamConsole():
82
+ if 'joined the game' in line:
83
+ print(line)
84
+
85
+ with server.console as console:
86
+ console.sendCommand('save-all')
87
+ console.waitFor('Saved the game')
88
+
89
+ server.onConsoleLine(print) # callbacks in a background thread
90
+ ```
91
+
92
+ ### Async
93
+
94
+ ```python
95
+ from calagoapi import AsyncPanel
96
+
97
+ async with AsyncPanel(url='https://panel.example.com', api_key='c7sp_...') as panel:
98
+ servers = await panel.servers.getServers()
99
+ statuses = await asyncio.gather(*(server.getStatus() for server in servers))
100
+
101
+ async for line in servers[0].streamConsole():
102
+ print(line)
103
+ ```
104
+
105
+ ### Files
106
+
107
+ ```python
108
+ for file in server.files.listFiles('/plugins'):
109
+ print(file.getName(), file.getSize(formatted=True))
110
+
111
+ properties = server.readFile('/server.properties')
112
+ server.writeFile('/eula.txt', 'eula=true')
113
+ server.files.uploadFile('/plugins', 'build/MyPlugin.jar')
114
+ server.files.downloadFile('/world.zip', 'world.zip')
115
+ ```
116
+
117
+ ### Backups
118
+
119
+ ```python
120
+ backup = server.createBackup('before-update')
121
+ backup.waitUntilComplete()
122
+
123
+ if backup.isSuccessful():
124
+ print(backup.getSize(formatted=True))
125
+
126
+ backup.lock()
127
+ backup.restore(truncate_directory=True)
128
+ ```
129
+
130
+ ### Schedules
131
+
132
+ ```python
133
+ from calagoapi import triggers, conditions, actions
134
+
135
+ server.schedules.createSchedule(
136
+ 'Nightly restart',
137
+ triggers=[triggers.cron('0 0 4 * * *')],
138
+ condition=conditions.serverState('running'),
139
+ steps=[
140
+ actions.sendCommand('say Restarting in 1 minute'),
141
+ actions.sleep(60_000),
142
+ actions.createBackup('nightly', foreground=True),
143
+ actions.sendPower('restart'),
144
+ ],
145
+ )
146
+ ```
147
+
148
+ ### Databases
149
+
150
+ ```python
151
+ db = server.createDatabase('stats')
152
+ print(db.getConnectionString())
153
+
154
+ db.explorer.createTable('players', [
155
+ {'name': 'id', 'type': 'INT', 'primary_key': True, 'auto_increment': True},
156
+ {'name': 'name', 'type': 'VARCHAR(32)'},
157
+ ])
158
+ db.explorer.insertRow('players', {'name': 'Steve'})
159
+ print(db.explorer.query('SELECT COUNT(*) FROM players'))
160
+ ```
161
+
162
+ ### Minecraft
163
+
164
+ ```python
165
+ server = panel.servers.getMinecraftServer('abc123')
166
+
167
+ server.say('Server update in 5 minutes!')
168
+ server.setProperties({'max-players': 100, 'motd': 'Welcome!'})
169
+ ```
170
+
171
+ ### Extensions
172
+
173
+ Optional features ship as separate packages and are switched on with `enable()`:
174
+
175
+ ```bash
176
+ pip install calagoapi-version-changer calagoapi-hungerbridge
177
+ ```
178
+
179
+ ```python
180
+ from calagoapi.extensions import enable
181
+
182
+ enable('version_changer')
183
+ latest = server.getBuilds('PAPER', '1.21.11', page=1, per_page=1)[0]
184
+ server.installVersion(latest)
185
+ print(server.installedVersion)
186
+
187
+ enable('hungerbridge', config={'token': 'bot:9f2c...'})
188
+ print(server.hungerbridge.players())
189
+ ```
190
+
191
+ Write your own: [docs/learning/creating_extensions.md](docs/learning/creating_extensions.md).
192
+
193
+ ### Administration
194
+
195
+ ```python
196
+ user = panel.admin.users.createUser('steve', 'steve@example.com')
197
+
198
+ server = panel.admin.servers.deployServer(
199
+ 'Steve SMP', owner=user, egg=panel.admin.nests.findEgg('Paper'),
200
+ locations=[panel.admin.locations.getLocationByName('Frankfurt')],
201
+ memory=4096, disk=20480,
202
+ )
203
+
204
+ for node in panel.admin.nodes.getNodes():
205
+ print(node.getName(), node.getSystemOverview()['version'])
206
+ ```
207
+
208
+ ### Errors
209
+
210
+ ```python
211
+ from calagoapi import NotFoundError, PermissionDeniedError, CalagoAPIError
212
+
213
+ try:
214
+ panel.servers.getServer('missing')
215
+ except NotFoundError:
216
+ print('No such server')
217
+ except CalagoAPIError as e:
218
+ print(e.status_code, e.errors)
219
+ ```
220
+
221
+ ## Documentation
222
+
223
+ The [docs](docs/) folder has a guide for every area:
224
+
225
+ - [Getting started](docs/getting-started.md)
226
+ - [Servers](docs/servers.md), [Minecraft servers](docs/minecraft.md), [Live console](docs/console.md)
227
+ - [Files](docs/files.md), [Backups](docs/backups.md), [Databases](docs/databases.md)
228
+ - [Schedules](docs/schedules.md)
229
+ - [Network, subusers and tunnels](docs/network.md)
230
+ - [Account and authentication](docs/account.md)
231
+ - [Administration](docs/admin.md)
232
+ - [Async](docs/async.md)
233
+ - [Errors, pagination and utilities](docs/errors-and-utilities.md)
234
+ - [Migrating from HungerLib](docs/migrating-from-hungerlib.md)
235
+ - [Architecture](docs/architecture.md)
236
+
237
+ Every public class and method also has a docstring with parameters and an
238
+ example, so `help(server.files)` works from a Python shell.
239
+
240
+ ## Development
241
+
242
+ ```bash
243
+ pip install -e .[dev]
244
+ pytest
245
+ ```
246
+
247
+ The tests run offline against `openapi.json` and a fake daemon. See
248
+ [Architecture](docs/architecture.md#tests).
249
+
250
+ ## License
251
+
252
+ GPL-3.0, see [LICENSE](LICENSE).
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "calagoapi"
10
- version = "1.0-dev.1"
10
+ version = "1.0-dev.3"
11
11
  description = "The Python SDK for Calagopus: servers, live console, files, backups, databases, schedules, nodes and full panel administration, sync and async."
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.9"
@@ -71,4 +71,5 @@ include = [
71
71
  [tool.pytest.ini_options]
72
72
  testpaths = [
73
73
  "tests",
74
+ "src/extensions",
74
75
  ]