squarecloud-api 3.6.1__tar.gz → 3.7.0__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 (20) hide show
  1. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/PKG-INFO +4 -3
  2. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/pyproject.toml +8 -3
  3. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/__init__.py +1 -1
  4. squarecloud_api-3.7.0/squarecloud/_internal/constants.py +3 -0
  5. squarecloud_api-3.7.0/squarecloud/_internal/decorators.py +12 -0
  6. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/app.py +11 -4
  7. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/client.py +27 -2
  8. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/data.py +17 -13
  9. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/http/http_client.py +2 -1
  10. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/listeners/__init__.py +7 -4
  11. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/listeners/capture_listener.py +4 -2
  12. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/listeners/request_listener.py +5 -1
  13. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/utils.py +3 -0
  14. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/LICENSE +0 -0
  15. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/README.md +0 -0
  16. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/errors.py +0 -0
  17. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/file.py +0 -0
  18. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/http/__init__.py +0 -0
  19. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/http/endpoints.py +0 -0
  20. {squarecloud_api-3.6.1 → squarecloud_api-3.7.0}/squarecloud/logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: squarecloud-api
3
- Version: 3.6.1
3
+ Version: 3.7.0
4
4
  Summary: SquareCloud API wrapper
5
5
  Home-page: https://github.com/squarecloudofc/wrapper-api-py
6
6
  License: MIT
@@ -13,8 +13,9 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
- Requires-Dist: aiohttp (==3.9.5)
17
- Requires-Dist: pydantic (>=2.5.2,<3.0.0)
16
+ Provides-Extra: pydantic
17
+ Requires-Dist: aiohttp (==3.10.2)
18
+ Requires-Dist: pydantic (>=2.8.2,<3.0.0) ; extra == "pydantic"
18
19
  Requires-Dist: taskipy (>=1.13.0,<2.0.0)
19
20
  Project-URL: Documentation, https://docs.squarecloud.app/sdks/py
20
21
  Project-URL: Repository, https://github.com/squarecloudofc/wrapper-api-py
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = 'squarecloud-api'
3
- version = '3.6.1'
3
+ version = '3.7.0'
4
4
  description = 'SquareCloud API wrapper'
5
5
  authors = ['Robert Nogueira <robertlucasnogueira@gmail.com>']
6
6
  repository = 'https://github.com/squarecloudofc/wrapper-api-py'
@@ -11,9 +11,12 @@ packages = [{ include = 'squarecloud' }]
11
11
 
12
12
  [tool.poetry.dependencies]
13
13
  python = '^3.9'
14
- aiohttp = "3.9.5"
15
- pydantic = '^2.5.2'
14
+ aiohttp = "3.10.2"
16
15
  taskipy = "^1.13.0"
16
+ pydantic = {version = "^2.8.2", optional = true}
17
+
18
+ [tool.poetry.extras]
19
+ pydantic = ["pydantic"]
17
20
 
18
21
  [tool.poetry.group.dev.dependencies]
19
22
  pytest = '^7.4.3'
@@ -26,6 +29,8 @@ ruff = '^0.0.289'
26
29
  memory-profiler = '^0.61.0'
27
30
  requests = '^2.31.0'
28
31
  pytest-rerunfailures = "^13.0"
32
+ python-dotenv = "^1.0.1"
33
+ rich = "^13.7.1"
29
34
 
30
35
  [build-system]
31
36
  requires = ['poetry-core']
@@ -21,4 +21,4 @@ from .data import (
21
21
  from .file import File
22
22
  from .http.endpoints import Endpoint
23
23
 
24
- __version__ = '3.6.1'
24
+ __version__ = '3.7.0'
@@ -0,0 +1,3 @@
1
+ from importlib.util import find_spec
2
+
3
+ USING_PYDANTIC = bool(find_spec('pydantic'))
@@ -0,0 +1,12 @@
1
+ from .constants import USING_PYDANTIC
2
+
3
+ if USING_PYDANTIC:
4
+ from pydantic import ConfigDict, validate_call
5
+
6
+
7
+ def validate(func: callable) -> callable:
8
+ if USING_PYDANTIC:
9
+ return validate_call(
10
+ func, config=ConfigDict(arbitrary_types_allowed=True)
11
+ )
12
+ return func
@@ -4,10 +4,9 @@ from functools import wraps
4
4
  from io import BytesIO
5
5
  from typing import TYPE_CHECKING, Any, Callable
6
6
 
7
- from pydantic import PositiveInt
8
-
9
7
  from squarecloud import errors
10
8
 
9
+ from ._internal.decorators import validate
11
10
  from .data import (
12
11
  AppData,
13
12
  Backup,
@@ -170,7 +169,7 @@ class Application(CaptureListenerManager):
170
169
  http: HTTPClient,
171
170
  id: str,
172
171
  name: str,
173
- ram: PositiveInt,
172
+ ram: int,
174
173
  lang: str,
175
174
  cluster: str,
176
175
  domain: str | None,
@@ -203,7 +202,7 @@ class Application(CaptureListenerManager):
203
202
  self._domain: str | None = domain
204
203
  self._custom: str | None = custom
205
204
  self._desc: str | None = desc
206
- self._ram: PositiveInt = ram
205
+ self._ram: int = ram
207
206
  self._lang: str = lang
208
207
  self._cluster: str = cluster
209
208
  self._client: 'Client' = client
@@ -528,6 +527,7 @@ class Application(CaptureListenerManager):
528
527
  )
529
528
  return response
530
529
 
530
+ @validate
531
531
  async def commit(self, file: File) -> Response:
532
532
  """
533
533
  The commit function is used to commit the application.
@@ -543,6 +543,7 @@ class Application(CaptureListenerManager):
543
543
  )
544
544
  return response
545
545
 
546
+ @validate
546
547
  async def files_list(self, path: str) -> list[FileInfo]:
547
548
  """
548
549
  The files_list function returns a list of files and folders in the
@@ -560,6 +561,7 @@ class Application(CaptureListenerManager):
560
561
  )
561
562
  return response
562
563
 
564
+ @validate
563
565
  async def read_file(self, path: str) -> BytesIO:
564
566
  """
565
567
  The read_file function reads the contents of a file from an app.
@@ -574,6 +576,7 @@ class Application(CaptureListenerManager):
574
576
  )
575
577
  return response
576
578
 
579
+ @validate
577
580
  async def create_file(self, file: File, path: str) -> Response:
578
581
 
579
582
  """
@@ -593,6 +596,7 @@ class Application(CaptureListenerManager):
593
596
  )
594
597
  return response
595
598
 
599
+ @validate
596
600
  async def delete_file(self, path: str) -> Response:
597
601
  """
598
602
  The delete_file function deletes a file from the app.
@@ -622,6 +626,7 @@ class Application(CaptureListenerManager):
622
626
  )
623
627
  return response
624
628
 
629
+ @validate
625
630
  async def github_integration(self, access_token: str) -> str:
626
631
  """
627
632
  The create_github_integration function returns a webhook to integrate
@@ -644,6 +649,7 @@ class Application(CaptureListenerManager):
644
649
  )
645
650
  return analytics
646
651
 
652
+ @validate
647
653
  async def set_custom_domain(self, custom_domain: str):
648
654
  response: Response = await self.client.set_custom_domain(
649
655
  self.id, custom_domain, avoid_listener=True
@@ -654,6 +660,7 @@ class Application(CaptureListenerManager):
654
660
  backups: list[BackupInfo] = await self.client.all_app_backups(self.id)
655
661
  return backups
656
662
 
663
+ @validate
657
664
  async def move_file(self, origin: str, dest: str):
658
665
  return await self.client.move_app_file(self.id, origin, dest)
659
666
 
@@ -7,6 +7,7 @@ from typing import Any, Callable, Literal, ParamSpec, TextIO, TypeVar
7
7
 
8
8
  from typing_extensions import deprecated
9
9
 
10
+ from ._internal.decorators import validate
10
11
  from .app import Application
11
12
  from .data import (
12
13
  AppData,
@@ -253,6 +254,7 @@ class Client(RequestListenerManager):
253
254
 
254
255
  return logs_data
255
256
 
257
+ @validate
256
258
  @_notify_listener(Endpoint.app_status())
257
259
  async def app_status(self, app_id: str, **_kwargs) -> StatusData:
258
260
  """
@@ -274,6 +276,7 @@ class Client(RequestListenerManager):
274
276
  payload: dict[str, Any] = response.response
275
277
  return StatusData(**payload)
276
278
 
279
+ @validate
277
280
  @_notify_listener(Endpoint.start())
278
281
  async def start_app(self, app_id: str, **_kwargs) -> Response:
279
282
  """
@@ -293,6 +296,7 @@ class Client(RequestListenerManager):
293
296
  """
294
297
  return await self._http.start_application(app_id)
295
298
 
299
+ @validate
296
300
  @_notify_listener(Endpoint.stop())
297
301
  async def stop_app(self, app_id: str, **_kwargs) -> Response:
298
302
  """
@@ -312,6 +316,7 @@ class Client(RequestListenerManager):
312
316
  """
313
317
  return await self._http.stop_application(app_id)
314
318
 
319
+ @validate
315
320
  @_notify_listener(Endpoint.restart())
316
321
  async def restart_app(self, app_id: str, **_kwargs) -> Response:
317
322
  """
@@ -331,6 +336,7 @@ class Client(RequestListenerManager):
331
336
  """
332
337
  return await self._http.restart_application(app_id)
333
338
 
339
+ @validate
334
340
  @_notify_listener(Endpoint.backup())
335
341
  async def backup(self, app_id: str, **_kwargs) -> Backup:
336
342
  """
@@ -354,6 +360,7 @@ class Client(RequestListenerManager):
354
360
 
355
361
  # async def app_backups(self) -> list[BackupInfo]:
356
362
 
363
+ @validate
357
364
  @_notify_listener(Endpoint.delete_app())
358
365
  async def delete_app(self, app_id: str, **_kwargs) -> Response:
359
366
  """
@@ -373,6 +380,7 @@ class Client(RequestListenerManager):
373
380
  """
374
381
  return await self._http.delete_application(app_id)
375
382
 
383
+ @validate
376
384
  @_notify_listener(Endpoint.commit())
377
385
  async def commit(self, app_id: str, file: File, **_kwargs) -> Response:
378
386
  """
@@ -393,6 +401,7 @@ class Client(RequestListenerManager):
393
401
  """
394
402
  return await self._http.commit(app_id, file)
395
403
 
404
+ @validate
396
405
  @_notify_listener(Endpoint.user())
397
406
  async def app(self, app_id: str, **_kwargs) -> Application:
398
407
  """
@@ -454,6 +463,7 @@ class Client(RequestListenerManager):
454
463
  apps.append(Application(client=self, http=self._http, **data))
455
464
  return apps
456
465
 
466
+ @validate
457
467
  @_notify_listener(Endpoint.upload())
458
468
  async def upload_app(self, file: File, **_kwargs) -> UploadData:
459
469
  """
@@ -508,6 +518,7 @@ class Client(RequestListenerManager):
508
518
  payload: dict[str, Any] = response.response
509
519
  return UploadData(**payload)
510
520
 
521
+ @validate
511
522
  @_notify_listener(Endpoint.files_list())
512
523
  async def app_files_list(
513
524
  self, app_id: str, path: str, **_kwargs
@@ -538,6 +549,7 @@ class Client(RequestListenerManager):
538
549
  for data in response.response
539
550
  ]
540
551
 
552
+ @validate
541
553
  @_notify_listener(Endpoint.files_read())
542
554
  async def read_app_file(
543
555
  self, app_id: str, path: str, **_kwargs
@@ -563,6 +575,7 @@ class Client(RequestListenerManager):
563
575
  if response.response:
564
576
  return BytesIO(bytes(response.response.get('data')))
565
577
 
578
+ @validate
566
579
  @_notify_listener(Endpoint.files_create())
567
580
  async def create_app_file(
568
581
  self, app_id: str, file: File, path: str, **_kwargs
@@ -597,6 +610,7 @@ class Client(RequestListenerManager):
597
610
 
598
611
  return response
599
612
 
613
+ @validate
600
614
  @_notify_listener(Endpoint.files_delete())
601
615
  async def delete_app_file(
602
616
  self, app_id: str, path: str, **_kwargs
@@ -620,6 +634,7 @@ class Client(RequestListenerManager):
620
634
  """
621
635
  return await self._http.file_delete(app_id, path)
622
636
 
637
+ @validate
623
638
  @_notify_listener(Endpoint.app_data())
624
639
  async def app_data(self, app_id: str, **_kwargs) -> AppData:
625
640
  """
@@ -640,6 +655,7 @@ class Client(RequestListenerManager):
640
655
  response: Response = await self._http.get_app_data(app_id)
641
656
  return AppData(**response.response)
642
657
 
658
+ @validate
643
659
  @_notify_listener(Endpoint.last_deploys())
644
660
  async def last_deploys(
645
661
  self, app_id: str, **_kwargs
@@ -664,6 +680,7 @@ class Client(RequestListenerManager):
664
680
  data = response.response
665
681
  return [[DeployData(**deploy) for deploy in _] for _ in data]
666
682
 
683
+ @validate
667
684
  @_notify_listener(Endpoint.github_integration())
668
685
  async def github_integration(
669
686
  self, app_id: str, access_token: str, **_kwargs
@@ -692,6 +709,7 @@ class Client(RequestListenerManager):
692
709
  data = response.response
693
710
  return data.get('webhook')
694
711
 
712
+ @validate
695
713
  @_notify_listener(Endpoint.custom_domain())
696
714
  async def set_custom_domain(
697
715
  self, app_id: str, custom_domain: str, **_kwargs
@@ -717,6 +735,7 @@ class Client(RequestListenerManager):
717
735
  app_id=app_id, custom_domain=custom_domain
718
736
  )
719
737
 
738
+ @validate
720
739
  @_notify_listener(Endpoint.domain_analytics())
721
740
  async def domain_analytics(
722
741
  self, app_id: str, **_kwargs
@@ -742,6 +761,7 @@ class Client(RequestListenerManager):
742
761
 
743
762
  return DomainAnalytics(**response.response)
744
763
 
764
+ @validate
745
765
  @_notify_listener(Endpoint.all_backups())
746
766
  async def all_app_backups(
747
767
  self, app_id: str, **_kwargs
@@ -760,6 +780,7 @@ class Client(RequestListenerManager):
760
780
  all_status.append(ResumedStatus(**status))
761
781
  return all_status
762
782
 
783
+ @validate
763
784
  @_notify_listener(Endpoint.move_file())
764
785
  async def move_app_file(
765
786
  self, app_id: str, origin: str, dest: str, **_kwargs
@@ -769,12 +790,16 @@ class Client(RequestListenerManager):
769
790
  )
770
791
  return response
771
792
 
793
+ @validate
772
794
  @_notify_listener(Endpoint.dns_records())
773
795
  async def dns_records(self, app_id: str) -> list[DNSRecord]:
774
796
  response: Response = await self._http.dns_records(app_id)
775
797
  return [DNSRecord(**data) for data in response.response]
776
798
 
799
+ @validate
777
800
  @_notify_listener(Endpoint.current_integration())
778
801
  async def current_app_integration(self, app_id: str) -> str | None:
779
- response: Response = await self._http.current_app_integration(app_id)
780
- return response.response
802
+ response: Response = await self._http.get_app_current_integration(
803
+ app_id
804
+ )
805
+ return response.response['webhook']
@@ -3,8 +3,12 @@ from __future__ import annotations
3
3
  from datetime import datetime
4
4
  from typing import Any, Dict, Literal, Optional
5
5
 
6
- from pydantic import confloat, conint
7
- from pydantic.dataclasses import dataclass
6
+ from ._internal.constants import USING_PYDANTIC
7
+
8
+ if USING_PYDANTIC:
9
+ from pydantic.dataclasses import dataclass
10
+ else:
11
+ from dataclasses import dataclass
8
12
 
9
13
 
10
14
  @dataclass(frozen=True)
@@ -67,9 +71,9 @@ class StatusData:
67
71
  running: bool
68
72
  storage: str
69
73
  network: Dict[str, Any]
70
- requests: conint(ge=0)
71
- uptime: conint(ge=0) | None = None
72
- time: conint(ge=0) | None = None
74
+ requests: int
75
+ uptime: int | None = None
76
+ time: int | None = None
73
77
 
74
78
  def to_dict(self):
75
79
  return self.__dict__.copy()
@@ -107,7 +111,7 @@ class AppData:
107
111
  id: str
108
112
  name: str
109
113
  cluster: str
110
- ram: confloat(ge=0)
114
+ ram: float
111
115
  language: Optional[str]
112
116
  cluster: str
113
117
  domain: str | None = None
@@ -128,13 +132,13 @@ class UserData:
128
132
  :ivar plan: User plan
129
133
  :ivar email: User email
130
134
 
131
- :type id: conint(ge=0)
135
+ :type id: int
132
136
  :type name: str
133
137
  :type plan: PlanData
134
138
  :type email: str | None = None
135
139
  """
136
140
 
137
- id: conint(ge=0)
141
+ id: int
138
142
  name: str
139
143
  plan: PlanData
140
144
  email: str | None = None
@@ -253,9 +257,9 @@ class UploadData:
253
257
  id: str
254
258
  name: str
255
259
  language: Language
256
- ram: confloat(ge=0)
257
- cpu: confloat(ge=0)
258
- subdomain: str | None = None
260
+ ram: float
261
+ cpu: float
262
+ domain: str | None = None
259
263
  description: str | None = None
260
264
 
261
265
  def to_dict(self):
@@ -283,9 +287,9 @@ class FileInfo:
283
287
  app_id: str
284
288
  type: Literal['file', 'directory']
285
289
  name: str
286
- lastModified: conint(ge=0) | float
290
+ lastModified: int | float
287
291
  path: str
288
- size: confloat(ge=0.0) = 0.0
292
+ size: int = 0
289
293
 
290
294
  def to_dict(self):
291
295
  return self.__dict__.copy()
@@ -216,6 +216,7 @@ class HTTPClient:
216
216
  log_level = logging.ERROR
217
217
  error = TooManyRequests
218
218
  case _:
219
+ log_level = logging.ERROR
219
220
  error = RequestError
220
221
 
221
222
  if _ := _get_error(code):
@@ -737,7 +738,7 @@ class HTTPClient:
737
738
  :raises TooManyRequestsError: Raised when the request status
738
739
  code is 429
739
740
  """
740
- route: Router = Router(Endpoint.current_webhook(), app_id=app_id)
741
+ route: Router = Router(Endpoint.current_integration(), app_id=app_id)
741
742
  response: Response = await self.request(route)
742
743
  return response
743
744
 
@@ -4,8 +4,11 @@ from dataclasses import dataclass
4
4
  from types import MappingProxyType
5
5
  from typing import TYPE_CHECKING, Any, Callable, Optional, Type, Union
6
6
 
7
- import pydantic
8
- from pydantic import BaseModel
7
+ from .._internal.constants import USING_PYDANTIC
8
+
9
+ if USING_PYDANTIC:
10
+ import pydantic
11
+ from pydantic import BaseModel
9
12
 
10
13
  from .. import data, errors
11
14
  from ..http.endpoints import Endpoint
@@ -137,9 +140,9 @@ class ListenerManager:
137
140
 
138
141
  @classmethod
139
142
  def cast_to_pydantic_model(
140
- cls, model: Type[BaseModel], values: dict[Any, Any]
143
+ cls, model: Type['BaseModel'], values: dict[Any, Any]
141
144
  ):
142
- result: BaseModel | None | dict = values
145
+ result: 'BaseModel' | None | dict = values
143
146
  if isinstance(model, types.UnionType):
144
147
  for ty in model.__args__:
145
148
  if ty is None:
@@ -3,12 +3,14 @@ import logging
3
3
  import types
4
4
  from typing import Any, Union
5
5
 
6
- import pydantic
7
-
8
6
  from .. import data, errors
7
+ from .._internal.constants import USING_PYDANTIC
9
8
  from ..http import Endpoint
10
9
  from . import Listener, ListenerManager
11
10
 
11
+ if USING_PYDANTIC:
12
+ import pydantic
13
+
12
14
  ListenerDataTypes = Union[
13
15
  data.AppData,
14
16
  data.StatusData,
@@ -3,7 +3,10 @@ import logging
3
3
  import types
4
4
  from typing import Any
5
5
 
6
- import pydantic
6
+ from .._internal.constants import USING_PYDANTIC
7
+
8
+ if USING_PYDANTIC:
9
+ import pydantic
7
10
 
8
11
  from ..http import Endpoint, Response
9
12
  from . import ListenerManager
@@ -62,6 +65,7 @@ class RequestListenerManager(ListenerManager):
62
65
  call_extra_param is not None
63
66
  and annotation is not None
64
67
  and annotation != call_extra_param.empty
68
+ and USING_PYDANTIC
65
69
  ):
66
70
  annotation: Any = call_extra_param.annotation
67
71
  cast_result = self.cast_to_pydantic_model(annotation, extra)
@@ -1,5 +1,7 @@
1
1
  from typing import Any, Literal
2
2
 
3
+ from squarecloud._internal.decorators import validate
4
+
3
5
 
4
6
  class ConfigFile:
5
7
  """
@@ -8,6 +10,7 @@ class ConfigFile:
8
10
  https://docs.squarecloud.app/articles/how-to-create-your-squarecloud-configuration-file
9
11
  """
10
12
 
13
+ @validate
11
14
  def __init__(
12
15
  self,
13
16
  display_name: str,
File without changes