qmenta-client 2.2.0.dev1523__tar.gz → 3.0.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qmenta-client
3
- Version: 2.2.0.dev1523
3
+ Version: 3.0.0
4
4
  Summary: Python client lib to interact with the QMENTA platform.
5
5
  Author: QMENTA
6
6
  Author-email: dev@qmenta.com
@@ -14,5 +14,5 @@ Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Requires-Dist: future (>=0.18.2,<0.19.0)
16
16
  Requires-Dist: pytest-cov (>=6.1.1,<7.0.0)
17
- Requires-Dist: qmenta-core (==4.1.1)
17
+ Requires-Dist: qmenta-core (==5.0.0)
18
18
  Project-URL: Homepage, https://www.qmenta.com/
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "qmenta-client"
3
- version = "2.2.0.dev1523"
3
+ version = "3.0.0"
4
4
  description = "Python client lib to interact with the QMENTA platform."
5
5
  authors = ["QMENTA <dev@qmenta.com>"]
6
6
  homepage = "https://www.qmenta.com/"
@@ -15,7 +15,7 @@ packages = [
15
15
  [tool.poetry.dependencies]
16
16
  python = "^3.10"
17
17
  future = "^0.18.2"
18
- qmenta-core = "4.1.1"
18
+ qmenta-core = "5.0.0"
19
19
  pytest-cov = "^6.1.1"
20
20
 
21
21
  [tool.poetry.group.dev.dependencies]
@@ -3,6 +3,7 @@ from __future__ import print_function
3
3
  import logging
4
4
  from qmenta.core import errors
5
5
  from qmenta.core import platform
6
+ from qmenta.core.auth import InvalidLoginError
6
7
  from urllib3.exceptions import HTTPError
7
8
 
8
9
  from .Project import Project
@@ -19,14 +20,27 @@ class Account:
19
20
 
20
21
  Parameters
21
22
  ----------
22
- username : str
23
+ username : str, optional
23
24
  Username on the platform. To get one go to https://platform.qmenta.com
24
- password : str
25
+ password : str, optional
25
26
  The password assigned to the username.
26
27
  base_url : str
27
28
  The base url of the platform.
28
29
  verify_certificates : bool
29
30
  verify SSL certificates?
31
+ api_key : str, optional
32
+ The API-KEY associated to the user.
33
+
34
+ Valid credential combinations
35
+ -----------------------------
36
+ username + password
37
+ Classic login. If two-factor authentication (2FA) is enabled on the
38
+ account, the user is prompted for the code interactively.
39
+ api_key
40
+ API-key login. 2FA is not required.
41
+ username + password + api_key
42
+ All three values are forwarded to the authentication layer, which
43
+ decides which credential to use.
30
44
 
31
45
  Attributes
32
46
  ----------
@@ -36,15 +50,17 @@ class Account:
36
50
 
37
51
  def __init__(
38
52
  self,
39
- username,
40
- password,
53
+ username=None,
54
+ password=None,
41
55
  base_url="https://platform.qmenta.com",
42
56
  verify_certificates=True,
57
+ api_key=None,
43
58
  ):
44
59
 
45
60
  self._cookie = None
46
61
  self.username = username
47
62
  self.password = password
63
+ self.api_key = api_key
48
64
  self.baseurl = base_url
49
65
  self.verify_certificates = verify_certificates
50
66
  self.auth = None
@@ -58,21 +74,37 @@ class Account:
58
74
  """
59
75
  Login to the platform.
60
76
 
77
+ Uses the credentials set on the instance (``username``/``password``
78
+ and/or ``api_key``). Valid combinations:
79
+
80
+ - ``username`` + ``password``: classic login. If 2FA is enabled on
81
+ the account, the user is prompted for the code interactively.
82
+ - ``api_key``: API-key login. 2FA is not required.
83
+ - ``username`` + ``password`` + ``api_key``: all values are forwarded
84
+ to the authentication layer, which decides which credential to use.
85
+
61
86
  Raises
62
87
  ------
88
+ qmenta.core.auth.InvalidLoginError
89
+ When the provided credentials are invalid.
63
90
  qmenta.core.platform.ConnectionError
64
91
  When the connection to the platform fails.
65
- qmenta.core.platform.InvalidLoginError
66
- When invalid credentials are provided.
92
+ qmenta.core.errors.PlatformError
93
+ When the platform returns an unexpected error.
67
94
  """
68
95
  logger = logging.getLogger(logger_name)
69
96
  try:
70
97
  auth = platform.Auth.login(
71
- self.username,
72
- self.password,
98
+ username=self.username,
99
+ password=self.password,
100
+ api_key=self.api_key,
73
101
  base_url=self.baseurl,
74
102
  ask_for_2fa_input=True,
75
103
  )
104
+ except InvalidLoginError as e:
105
+ logger.error("Failed to log in: {}".format(e))
106
+ self.auth = None
107
+ raise
76
108
  except errors.PlatformError as e:
77
109
  logger.error("Failed to log in: {}".format(e))
78
110
  self.auth = None
@@ -656,13 +656,15 @@ class Project:
656
656
  'change_subject_metadata()' method.
657
657
 
658
658
  Example:
659
- dictionary {"param_name":
660
- { "order": Int,
661
- "tags": [tag1, tag2, ..., ],
662
- "title: "Title",
663
- "type": "integer|string|date|list|decimal",
664
- "visible": 0|1
665
- }
659
+ dictionary = {
660
+ "param_name":
661
+ {
662
+ "order": Int,
663
+ "tags": [tag1, tag2, ..., ],
664
+ "title": "Title",
665
+ "type": "integer|string|date|list|decimal",
666
+ "visible": 0|1
667
+ }
666
668
  }
667
669
 
668
670
  Returns
@@ -1485,7 +1487,7 @@ class Project:
1485
1487
  - secret_name: str or None Subject ID
1486
1488
  - tags: str or None
1487
1489
  - with_child_analysis: 1 or None if 1, child analysis of workflows
1488
- will appear
1490
+ will appear
1489
1491
  - id: str or None ID
1490
1492
  - state: running, completed, pending, exception or None
1491
1493
  - username: str or None
@@ -1717,7 +1719,7 @@ class Project:
1717
1719
  - secret_name: str or None Subject ID
1718
1720
  - tags: str or None
1719
1721
  - with_child_analysis: 1 or None if 1, child analysis of workflows
1720
- will appear
1722
+ will appear
1721
1723
  - id: int or None ID
1722
1724
  - state: running, completed, pending, exception or None
1723
1725
  - username: str or None
@@ -2462,18 +2464,17 @@ class Project:
2462
2464
 
2463
2465
  Returns:
2464
2466
  dict: A dictionary containing comprehensive QC statistics
2465
- including:
2466
2467
  - passed_rules: Total count of passed rules across all subjects
2467
2468
  - failed_rules: Total count of failed rules across all subjects
2468
2469
  - subjects_passed: Count of subjects with no failed rules
2469
2470
  - subjects_with_failed: Count of subjects with at least one
2470
- failed rule
2471
+ failed rule
2471
2472
  - num_passed_files_distribution: Distribution of how many
2472
- rules have N passed files
2473
+ rules have N passed files
2473
2474
  - file_stats: File-level statistics (total, passed, failed,
2474
- pass percentage)
2475
+ pass percentage)
2475
2476
  - condition_failure_rates: Frequency and percentage of each
2476
- failed condition
2477
+ failed condition
2477
2478
  - rule_success_rates: Success rates for each rule type
2478
2479
 
2479
2480
  The statistics help identify:
@@ -2610,15 +2611,17 @@ class Project:
2610
2611
  # Calculate condition failure percentages
2611
2612
  for condition in stats["condition_failure_rates"]:
2612
2613
  if total_failures > 0:
2613
- stats["condition_failure_rates"][condition][
2614
- "percentage"
2615
- ] = round(
2616
- (
2617
- stats["condition_failure_rates"][condition]["count"]
2618
- / total_failures
2614
+ stats["condition_failure_rates"][condition]["percentage"] = (
2615
+ round(
2616
+ (
2617
+ stats["condition_failure_rates"][condition][
2618
+ "count"
2619
+ ]
2620
+ / total_failures
2621
+ )
2622
+ * 100,
2623
+ 2,
2619
2624
  )
2620
- * 100,
2621
- 2,
2622
2625
  )
2623
2626
 
2624
2627
  # Calculate rule success rates