3030
3131
3232DEFAULT_PAGINATION_LIMIT = 20
33-
33+ """int: Defines the default limit for pagination, set to `20`."""
3434
3535class FileTransferStatus (str , Enum ):
36+ """Represents the status of a file transfer.
37+
38+ Attributes:
39+ PENDING (str): The transfer is pending.
40+ SUCCESS (str): The transfer was successful.
41+ FAILED (str): The transfer failed.
42+ """
3643 PENDING = "PENDING"
3744 SUCCESS = "SUCCESS"
3845 FAILED = "FAILED"
3946
4047
4148class FileTransferType (Enum ):
49+ """Represents the type of file transfer.
50+
51+ Attributes:
52+ PROJECT (str): Refers to a project file.
53+ PACKAGE (str): Refers to a package Type.
54+ """
4255 PROJECT = "project"
4356 PACKAGE = "package"
4457
4558
4659class JobTypes (str , Enum ):
60+ """Represents the types of jobs that can be processed on QFieldCloud.
61+
62+ Attributes:
63+ PACKAGE (str): Refers to a packaging job.
64+ APPLY_DELTAS (str): Refers to applying deltas (differences).
65+ PROCESS_PROJECTFILE (str): Refers to processing a project file.
66+ """
4767 PACKAGE = "package"
4868 APPLY_DELTAS = "delta_apply"
4969 PROCESS_PROJECTFILE = "process_projectfile"
5070
5171
5272class ProjectCollaboratorRole (str , Enum ):
73+ """Defines roles for project collaborators.
74+
75+ Attributes:
76+ ADMIN (str): Administrator role.
77+ MANAGER (str): Manager role.
78+ EDITOR (str): Editor role.
79+ REPORTER (str): Reporter role.
80+ READER (str): Reader role.
81+ """
5382 ADMIN = "admin"
5483 MANAGER = "manager"
5584 EDITOR = "editor"
@@ -58,11 +87,28 @@ class ProjectCollaboratorRole(str, Enum):
5887
5988
6089class OrganizationMemberRole (str , Enum ):
90+ """Defines roles for organization members.
91+
92+ Attributes:
93+ ADMIN (str): Administrator role.
94+ MEMBER (str): Member role.
95+ """
6196 ADMIN = "admin"
6297 MEMBER = "member"
6398
6499
65100class CollaboratorModel (TypedDict ):
101+ """Represents the structure of a project collaborator in the QFieldCloud system.
102+
103+ Attributes:
104+ collaborator (str): The collaborator's identifier.
105+ role (ProjectCollaboratorRole): The role of the collaborator.
106+ project_id (str): The associated project identifier.
107+ created_by (str): The user who created the collaborator entry.
108+ updated_by (str): The user who last updated the collaborator entry.
109+ created_at (datetime.datetime): The timestamp when the collaborator entry was created.
110+ updated_at (datetime.datetime): The timestamp when the collaborator entry was last updated.
111+ """
66112 collaborator : str
67113 role : ProjectCollaboratorRole
68114 project_id : str
@@ -73,41 +119,90 @@ class CollaboratorModel(TypedDict):
73119
74120
75121class OrganizationMemberModel (TypedDict ):
122+ """Represents the structure of an organization member in the QFieldCloud system.
123+
124+ Attributes:
125+ member (str): The member's identifier.
126+ role (OrganizationMemberRole): The role of the member.
127+ organization (str): The associated organization identifier.
128+ is_public (bool): A boolean indicating if the membership is public.
129+
130+ Todo:
131+ * Future work that can be surely expected, check QF-4535
132+ """
76133 member : str
77134 role : OrganizationMemberRole
78135 organization : str
79136 is_public : bool
80- # TODO future work that can be surely expected, check QF-4535
81137 # created_by: str
82138 # updated_by: str
83139 # created_at: datetime.datetime
84140 # updated_at: datetime.datetime
85141
86142
87143class Pagination :
144+ """The Pagination class allows for controlling and managing pagination of results within the QFieldCloud SDK.
145+
146+ Attributes:
147+ limit (Optional[int]): The maximum number of items to return.
148+ offset (Optional[int]): The starting point from which to return items.
149+ """
150+
88151 limit = None
89152 offset = None
90153
91154 def __init__ (
92155 self , limit : Optional [int ] = None , offset : Optional [int ] = None
93156 ) -> None :
157+ """Initializes the pagination settings.
158+
159+ Args:
160+ limit (Optional[int]): The maximum number of items to return. Defaults to None.
161+ offset (Optional[int]): The starting point from which to return items. Defaults to None.
162+ """
94163 self .limit = limit
95164 self .offset = offset
96165
97166 @property
98167 def is_empty (self ):
168+ """Checks if both limit and offset are None, indicating no pagination settings.
169+
170+ Returns:
171+ bool: True if both limit and offset are None, False otherwise.
172+ """
99173 return self .limit is None and self .offset is None
100174
101175
102176class Client :
177+ """The core component of the QFieldCloud SDK, providing methods for interacting with the QFieldCloud platform.
178+
179+ This class handles authentication, project management, file management, and more.
180+
181+ Attributes:
182+ session (requests.Session): The session object to maintain connections.
183+ url (str): The base URL for the QFieldCloud API.
184+ token (str): The authentication token for API access.
185+ verify_ssl (bool): Whether to verify SSL certificates.
186+ """
187+
103188 def __init__ (
104189 self , url : str = None , verify_ssl : bool = None , token : str = None
105190 ) -> None :
106191 """Prepares a new client.
107192
193+ If the `verify_ssl` is set to `False`, SSL warnings will be disabled. The session is configured with retries for GET requests on specific 5xx HTTP status codes.
194+
108195 If the `url` is not provided, uses `QFIELDCLOUD_URL` from the environment.
109196 If the `token` is not provided, uses `QFIELDCLOUD_TOKEN` from the environment.
110197 `session` will be reused between requests if the SDK is run as a library.
198+
199+ Args:
200+ url (Optional[str]): The base URL for the QFieldCloud API. Defaults to `QFIELDCLOUD_URL` environment variable if not provided.
201+ verify_ssl (Optional[bool]): Whether to verify SSL certificates. Defaults to True if not specified.
202+ token (Optional[str]): The authentication token for API access. Defaults to `QFIELDCLOUD_TOKEN` environment variable if not provided.
203+
204+ Raises:
205+ QfcException: If the `url` is not provided either directly or through the environment variable.
111206 """
112207 self .session = requests .Session ()
113208 # retries should be only on GET and only if error 5xx
@@ -138,6 +233,13 @@ def login(self, username: str, password: str) -> Dict:
138233 Args:
139234 username: the username or the email used to register
140235 password: the password associated with that username
236+
237+ Returns:
238+ Dict: A dictionary containing the authentication token and additional metadata.
239+
240+ Example:
241+ client = Client(url="https://app.qfield.cloud/api/v1/")
242+ client.login("ninjamaster", "secret_password123")
141243 """
142244 resp = self ._request (
143245 "POST" ,
@@ -156,7 +258,14 @@ def login(self, username: str, password: str) -> Dict:
156258 return payload
157259
158260 def logout (self ) -> None :
159- """Logout from the current session."""
261+ """Logout from the current session.
262+
263+ Returns:
264+ None
265+
266+ Example:
267+ client.logout()
268+ """
160269 resp = self ._request ("POST" , "auth/logout" )
161270
162271 return resp .json ()
@@ -170,6 +279,16 @@ def list_projects(
170279 """
171280 Returns a list of projects accessible to the current user,
172281 their own and optionally the public ones.
282+
283+ Args:
284+ include_public (Optional[bool]): Whether to include public projects in the list. Defaults to False.
285+ pagination (Pagination): Pagination settings for the request. Defaults to an empty Pagination instance.
286+
287+ Returns:
288+ List[Dict[str, Any]]: A list of dictionaries containing project details.
289+
290+ Example:
291+ client.list_projects()
173292 """
174293 params = {
175294 "include-public" : str (int (include_public )), # type: ignore
@@ -183,14 +302,28 @@ def list_projects(
183302 def list_remote_files (
184303 self , project_id : str , skip_metadata : bool = True
185304 ) -> List [Dict [str , Any ]]:
305+ """Lists the files available in the specified project.
306+
307+ Args:
308+ project_id (str): The ID of the project to list files for.
309+ skip_metadata (bool): Whether to skip fetching metadata for the files. Defaults to True.
310+
311+ Returns:
312+ List[Dict[str, Any]]: A list of dictionaries containing file details.
313+
314+ Example:
315+ client.list_remote_files("project_id", True)
316+
317+ Todo:
318+ * Remove this temporary decoration with `etag` key
319+ """
186320 params = {}
187321
188322 if skip_metadata :
189323 params ["skip_metadata" ] = "1"
190324
191325 resp = self ._request ("GET" , f"files/{ project_id } " , params = params )
192326 remote_files = resp .json ()
193- # TODO remove this temporary decoration with `etag` key
194327 remote_files = list (map (lambda f : {"etag" : f ["md5sum" ], ** f }, remote_files ))
195328
196329 return remote_files
@@ -202,6 +335,20 @@ def create_project(
202335 description : str = "" ,
203336 is_public : bool = False ,
204337 ) -> Dict :
338+ """Creates a new project in QFieldCloud.
339+
340+ Args:
341+ name (str): The name of the new project.
342+ owner (Optional[str]): The owner of the project. Defaults to None.
343+ description (Optional[str]): A description of the project. Defaults to an empty string.
344+ is_public (Optional[bool]): Whether the project should be public. Defaults to False.
345+
346+ Returns:
347+ Dict: A dictionary containing the details of the created project.
348+
349+ Example:
350+ client.create_project(name="my_project", is_public=False)
351+ """
205352 resp = self ._request (
206353 "POST" ,
207354 "projects" ,
0 commit comments