|
1 | 1 | [SquareCloud]: https://squarecloud.app |
2 | 2 |
|
3 | | -[API]: https://docs.squarecloud.app/api/introducao |
| 3 | +[SquareCloudAPI]: https://docs.squarecloud.app/api/introducao |
4 | 4 |
|
5 | 5 | [@alma]: https://github.com/Robert-Nogueira |
6 | 6 |
|
7 | 7 | # squarecloud-api |
8 | 8 |
|
9 | | -squarecloud-api is a wrapper of the [API] of [SquareCloud] made by [@alma] |
| 9 | +squarecloud-api is a wrapper for the [SquareCloudAPI] mainted by [@alma] |
| 10 | + |
10 | 11 |
|
11 | 12 | ## Installing |
12 | 13 |
|
13 | 14 | ```` |
14 | 15 | pip install squarecloud-api |
15 | 16 | ```` |
16 | 17 |
|
17 | | -## Starting |
18 | 18 |
|
19 | | -### Where to get my api key? |
| 19 | +## Getting api key |
20 | 20 |
|
21 | 21 | to get your api key/token just go to the [SquareCloud] website and |
22 | 22 | register/login, after that go |
23 | 23 | to `dashboard` > `my account` > `Regenerate API/CLI KEY` and copy the key. |
24 | 24 |
|
25 | | -### The client instance |
26 | | - |
27 | | -with the client you can get information about your application |
28 | | - |
29 | | -````python |
30 | | -import squarecloud as square |
31 | | - |
32 | | -client = square.Client(api_key='API KEY') |
33 | | - |
34 | | -app_id = 'application id' |
35 | | - |
36 | | - |
37 | | -async def example(): |
38 | | - logs = await client.get_logs(app_id) |
39 | | - print(logs) |
40 | | - |
41 | | - complete_logs = await client.get_logs(app_id) |
42 | | - print(complete_logs) |
43 | | - |
44 | | - status = await client.app_status(app_id) |
45 | | - print(status.ram) |
46 | | - print(status.cpu) |
47 | | - print(status.requests) |
48 | | - print(status.network) |
49 | | - print(status.running) |
50 | | - print(status.storage) |
51 | | - |
52 | | -```` |
53 | | - |
54 | | -you can also manage your application |
55 | | - |
56 | | -````python |
57 | | -import squarecloud as square |
58 | | - |
59 | | -# you can define if you want debug logs to be shown or not |
60 | | -# this value by default is True |
61 | | -client = square.Client(api_key='API KEY') |
62 | | - |
63 | | -app_id = 'application id' |
64 | | - |
65 | | - |
66 | | -async def example(): |
67 | | - await client.backup(app_id) |
68 | | - await client.start_app(app_id) |
69 | | - await client.stop_app(app_id) |
70 | | - await client.restart_app(app_id) |
71 | | - await client.delete_app(app_id) |
72 | | - await client.commit(app_id, file=square.File('path/to/your/file')) |
73 | | - |
74 | | -```` |
75 | | - |
76 | | -### Application object |
77 | | - |
78 | | -Using the client you can also get an application or a list of applications and |
79 | | -use them to manage your application. |
| 25 | +> ## [Documentation](docs/) |
| 26 | +> - [application](docs/application.md) |
| 27 | +> - [capture_listeners](docs/capture_listeners.md) |
| 28 | +> - [client](docs/client.md) |
| 29 | +> - [commit_and_upload](docs/commit_and_upload.md) |
| 30 | +> - [request_listeners](docs/request_listeners.md) |
80 | 31 |
|
81 | | -````python |
| 32 | +## Basict usage |
| 33 | +```python |
82 | 34 | import squarecloud as square |
| 35 | +import asyncio |
83 | 36 |
|
84 | | -client = square.Client(api_key='API KEY') |
85 | | - |
86 | | - |
87 | | -async def example(): |
88 | | - app = await client.app('application id') |
| 37 | +client = square.Client('API_KEY', debug=True) |
89 | 38 |
|
90 | | - # app information |
91 | | - status = await app.status() |
| 39 | +async def main(): |
| 40 | + status = await client.app_status(app_id='application_id') |
| 41 | + print(status) |
92 | 42 | print(status.ram) |
93 | 43 | print(status.cpu) |
94 | | - print(status.requests) |
95 | | - print(status.network) |
96 | | - print(status.running) |
97 | | - print(status.storage) |
98 | | - |
99 | | - # managing |
100 | | - await app.stop() |
101 | | - await app.start() |
102 | | - await app.restart() |
103 | | - await app.backup() |
104 | | - await app.delete() |
105 | | - await app.backup() |
106 | | - await app.commit(square.File('path/to/your/file')) |
107 | | - |
108 | | - apps_list = await client.all_apps() |
109 | | - for app in apps_list: |
110 | | - print(app) |
111 | | - |
112 | | -```` |
113 | | - |
114 | | -### Uploading an application |
115 | | - |
116 | | -to upload an application you need of a zip contain the following files: |
117 | | - |
118 | | -- the main file: the file responsible to start the application |
119 | | -- the dependency file: contains information about with dependencies need to be |
120 | | - installed |
121 | | -- the configuration file(squarecloud.app): a configuration file to upload, for |
122 | | - more information take a look at [this link](https://docs.squarecloud.app/suporte/como-hospedar#configurando-sua-aplicacao) |
123 | | - |
124 | | -```python |
125 | | -import squarecloud as square |
126 | | - |
127 | | -client = square.Client(api_key='API KEY') |
128 | 44 |
|
129 | | - |
130 | | -async def example(): |
131 | | - await client.upload_app(square.File('path/to/my_file.zip')) |
132 | | -``` |
133 | | -for your convenience a function was added to create the configuration file |
134 | | - |
135 | | -```python |
136 | | -import squarecloud as square |
137 | | - |
138 | | -# application example |
139 | | -square.create_config_file( |
140 | | - path='directory/to/save/', # the path where the file should be saved |
141 | | - display_name='an cool name', |
142 | | - description='an cool description', |
143 | | - main='main.py', |
144 | | - memory=100, |
145 | | - version='recommended', |
146 | | -) |
147 | | - |
148 | | -# website example |
149 | | -square.create_config_file( |
150 | | - path='directory/to/save', |
151 | | - display_name='cool website', |
152 | | - description='this is really cool', |
153 | | - main='index.js', |
154 | | - subdomain='coolwebsite.squareweb.app', |
155 | | - start='start this cool website', # if not static it is configurable |
156 | | - memory=512, |
157 | | - version='recommended', |
158 | | -) |
159 | | - |
160 | | -""" |
161 | | -[REQUIRED] parameters |
162 | | ---------------------- |
163 | | -path: str |
164 | | -display_name: str |
165 | | -main: str |
166 | | -memory: int |
167 | | -version: Literal['recommended', 'latest'] |
168 | | -
|
169 | | -[OPTIONAL] parameters |
170 | | ---------------------- |
171 | | -avatar: str | None = None |
172 | | -description: str | None = None |
173 | | -subdomain: str | None = None |
174 | | -start: str | None = None |
175 | | -""" |
| 45 | +asyncio.run(main()) |
176 | 46 | ``` |
177 | 47 |
|
178 | | - |
179 | | -### Debug mode |
180 | | -Every time a request is made logs are displayed in the terminal containing |
181 | | -useful information, You can disable this by setting the `debug` parameter to |
182 | | -False for the client, this value by default is True. |
183 | | - |
184 | | -````py |
185 | | -import squarecloud as square |
186 | | - |
187 | | -client = square.Client(api_key='API KEY', debug=False) # no logs |
188 | | -```` |
189 | | - |
190 | 48 | ## License |
191 | 49 |
|
192 | 50 | MIT License |
0 commit comments