curious-pyapi 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,5 @@
1
+ """Python API for Curious."""
2
+
3
+ from .api.curious import get_curious_token
4
+
5
+ __all__ = ["get_curious_token"]
@@ -0,0 +1,5 @@
1
+ """API for Curious."""
2
+
3
+ from .curious import get_curious_token
4
+
5
+ __all__ = ["get_curious_token"]
@@ -0,0 +1,81 @@
1
+ """Curious API functionality."""
2
+
3
+ import json
4
+ from typing import Optional
5
+ import httpx
6
+
7
+ from pydantic import AnyHttpUrl
8
+
9
+ from ..schema.pyapi import Tokens
10
+ from ..utils.defaults import CURIOUS_BASE_URL, headers
11
+ from ..utils.data import api_data
12
+ from ..utils.logging import get_logger
13
+
14
+ LOGGER = get_logger(__name__)
15
+
16
+
17
+ def get_curious_token(
18
+ curious_data: dict,
19
+ curious_headers: Optional[dict] = None,
20
+ curious_url: httpx.URL | AnyHttpUrl = CURIOUS_BASE_URL,
21
+ ) -> Optional[Tokens]:
22
+ """Process the response to a POST request to the specified URL.
23
+
24
+ Parameters
25
+ ----------
26
+ curious_data
27
+ The data to include in the POST request.
28
+ curious_headers
29
+ The headers to include in the POST request.
30
+ curious_url
31
+ The URL to send the POST request to.
32
+
33
+ Returns
34
+ -------
35
+ Tokens or None
36
+ An object containing (access, refresh) token strings, or None if unsuccessful.
37
+
38
+ Raises
39
+ ------
40
+ RuntimeError
41
+ If there is an error with the request or response.
42
+
43
+ """
44
+ curious_headers = headers(headers=curious_headers)
45
+ if isinstance(curious_url, str):
46
+ curious_url = httpx.URL(curious_url)
47
+ assert isinstance(curious_url, httpx.URL)
48
+ try:
49
+ # Sending the POST request
50
+ response = httpx.post(
51
+ curious_url.join("/auth/login"),
52
+ json=api_data(curious_data),
53
+ headers=curious_headers,
54
+ )
55
+ if response.status_code == httpx.codes.OK:
56
+ response_data = response.json() # Convert response to JSON
57
+ access_token = (
58
+ response_data.get("result", {})
59
+ .get("token", {})
60
+ .get("accessToken", None)
61
+ ) # Get access token
62
+ refresh_token = (
63
+ response_data.get("result", {})
64
+ .get("token", {})
65
+ .get("refreshToken", None)
66
+ ) # Get refresh token
67
+ else:
68
+ LOGGER.exception(
69
+ "Failed to fetch data: %d - %s", response.status_code, response.text
70
+ )
71
+ response.raise_for_status()
72
+ return None
73
+
74
+ return Tokens(access=access_token, refresh=refresh_token)
75
+
76
+ except httpx.HTTPError as e:
77
+ msg = f"Error sending request: {e}"
78
+ raise RuntimeError(msg) from e
79
+ except json.JSONDecodeError as e:
80
+ msg = f"Error: Response is not valid JSON! {e}"
81
+ raise RuntimeError(msg) from e
curious_pyapi/py.typed ADDED
File without changes
@@ -0,0 +1 @@
1
+ """Schemas for Curious and Curious-PyAPI."""
@@ -0,0 +1,68 @@
1
+ """Curious schemas."""
2
+
3
+ from typing import Annotated
4
+
5
+ import polars as pl
6
+ from pydantic.types import StringConstraints
7
+
8
+ from .regex import EMAIL_REGEX
9
+ from ..utils.logging import get_logger
10
+
11
+ LOGGER = get_logger(__name__)
12
+
13
+
14
+ @pl.api.register_dataframe_namespace("curious_pyapi")
15
+ class CuriousAccount:
16
+ SCHEMA = pl.Schema(
17
+ {
18
+ "email": pl.String,
19
+ "firstName": pl.String,
20
+ "lastName": pl.String,
21
+ "language": pl.String,
22
+ "secretUserId": pl.String,
23
+ "nickname": pl.String,
24
+ "tag": pl.String,
25
+ }
26
+ )
27
+
28
+ def __init__(self, df: pl.DataFrame):
29
+ self._df = df
30
+
31
+
32
+ def enforce_schema(self) -> pl.DataFrame:
33
+ """Enforces schema, adds missing columns with nulls, and casts types."""
34
+ exprs = [
35
+ pl.col(col).cast(dtype)
36
+ if col in self._df.columns
37
+ else pl.lit(None, dtype=dtype).alias(col)
38
+ for col, dtype in self.SCHEMA.items()
39
+ ]
40
+
41
+ out_df = self._df.select(exprs)
42
+
43
+ # Evaluate against out_df where 'email' is guaranteed to exist
44
+ is_valid_email = pl.col("email").str.contains(EMAIL_REGEX).fill_null(False)
45
+
46
+ failures_df = out_df.filter(~is_valid_email)
47
+ out_df = out_df.filter(is_valid_email)
48
+
49
+ if not failures_df.is_empty():
50
+ log_cols = [
51
+ col
52
+ for col in ["email", "secretUserId", "nickname"]
53
+ if col in failures_df.columns
54
+ ]
55
+ LOGGER.error(
56
+ "Dropped %d records due to invalid email addresses:\n%s",
57
+ failures_df.height,
58
+ failures_df.select(log_cols),
59
+ )
60
+
61
+ return out_df
62
+
63
+
64
+ CuriousId = Annotated[
65
+ str,
66
+ StringConstraints(pattern=r"^[a-zA-Z0-9]{8}(-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}$"),
67
+ ]
68
+ """ID string for a Curious entity."""
@@ -0,0 +1,29 @@
1
+ """Curious-PyAPI schemas."""
2
+
3
+ from pydantic import BaseModel, EmailStr, SecretStr
4
+
5
+ from .curious import CuriousId
6
+ from ..utils.logging import get_logger
7
+
8
+ logger = get_logger(__name__)
9
+
10
+
11
+ class CuriousAuth(BaseModel):
12
+ """Required data for authentication and decryption."""
13
+
14
+ curious_email: EmailStr
15
+ curious_password: SecretStr
16
+ applet_id: CuriousId
17
+ applet_password: SecretStr
18
+
19
+ @property
20
+ def login_credentials(self) -> dict[str, str | SecretStr]:
21
+ """Return email and password as dictionary for API request."""
22
+ return {"email": self.curious_email, "password": self.curious_password}
23
+
24
+
25
+ class Tokens(BaseModel):
26
+ """Curious tokens."""
27
+
28
+ access: SecretStr
29
+ refresh: SecretStr
@@ -0,0 +1,3 @@
1
+ """Global schema."""
2
+
3
+ EMAIL_REGEX = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
@@ -0,0 +1 @@
1
+ """Curious-PyAPI utilities."""
@@ -0,0 +1,11 @@
1
+ """Data utilities."""
2
+
3
+ from pydantic import SecretStr
4
+
5
+
6
+ def api_data(data: dict) -> dict:
7
+ """Prep data for API calls."""
8
+ return {
9
+ k: v.get_secret_value() if isinstance(v, SecretStr) else v
10
+ for k, v in data.items()
11
+ }
@@ -0,0 +1,16 @@
1
+ """Default values."""
2
+
3
+ from typing import Optional
4
+
5
+ from httpx import URL
6
+
7
+ CURIOUS_BASE_URL = URL("https://api-v2.gettingcurious.com")
8
+ """Canonical URL for Curious API."""
9
+
10
+
11
+ def headers(
12
+ token: Optional[str] = None, headers: Optional[dict] = None
13
+ ) -> dict[str, str]:
14
+ """Return Curious headers."""
15
+ auth = {"Authorization": f"Bearer {token}"} if token else {}
16
+ return {"Content-Type": "application/json"} | auth | (headers or {})
@@ -0,0 +1,8 @@
1
+ """Logging utilities."""
2
+
3
+ import logging
4
+
5
+
6
+ def get_logger(name: str) -> logging.Logger:
7
+ """Get Logger object."""
8
+ return logging.getLogger(name)
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.5
2
+ Name: curious-pyapi
3
+ Version: 0.1.0
4
+ Summary: Python interface for Curious API.
5
+ Author-email: Jon Cluce <jon.clucas@childmind.org>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.14
8
+ Requires-Dist: fastexcel>=0.21.0
9
+ Requires-Dist: httpx>=0.28.1
10
+ Requires-Dist: polars>=1.44.0
11
+ Requires-Dist: pydantic[email]>=2.13.4
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Curious-PyAPI
15
+
16
+ Python interfaces for Curious API.
17
+
18
+ Work-in-progress, with calls added as we use them.
@@ -0,0 +1,16 @@
1
+ curious_pyapi/__init__.py,sha256=sgS_xN-0tTip9sdcqCE5zbdj4K-tUbE68Ndto4goDV8,107
2
+ curious_pyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ curious_pyapi/api/__init__.py,sha256=YNUqXzLA4i2Bm43zB57-BrZc-eP02jWZ7e7BioqOxGE,96
4
+ curious_pyapi/api/curious.py,sha256=DPfza1VCIm0WE-BU5PTWQh4-1si3pynMtWoEHwM_LfY,2442
5
+ curious_pyapi/schema/__init__.py,sha256=8bWZXWv0Rvbm5UinVBlOjc7QILSSXyfLAtd1OntbHS8,45
6
+ curious_pyapi/schema/curious.py,sha256=tLynmstA8rXOrayEjR0FuIFxAouW3UqWszErO10alUI,1781
7
+ curious_pyapi/schema/pyapi.py,sha256=bbephKjYs9jr7EmTNMA-fXJnDQOL58ifPPwWej_VpGg,720
8
+ curious_pyapi/schema/regex.py,sha256=qvVvb57PsZ6euS_WlJUef9jBY8T7Da6TQxiedHgGPTo,88
9
+ curious_pyapi/utils/__init__.py,sha256=PqZNsxLVBIVEEx_vIp5xtnM0K3HPtFLgWTFKQxOwdOU,31
10
+ curious_pyapi/utils/data.py,sha256=_iHD2vluH7gyBCG3JQY4RwDzwLJQkusbAfcqpPxGrUc,244
11
+ curious_pyapi/utils/defaults.py,sha256=jlTJnqbMu8Y5I6Wq_SfrSW3tKUf2b6w5_9UhG_ZWdQI,444
12
+ curious_pyapi/utils/logging.py,sha256=dj1OWUQLRRHiit2PNwW1t6wh-KxJB4dOJaKlP6k9TNE,152
13
+ curious_pyapi-0.1.0.dist-info/METADATA,sha256=ZwFjmbAhS-_WL7ZQTnyF0AQWU-YXr1_x9SzHIU994kU,473
14
+ curious_pyapi-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
15
+ curious_pyapi-0.1.0.dist-info/licenses/LICENSE,sha256=Sf2NH6l_RwtdmPtvewFiAg3o3gV5mogv4iE3O118PuY,1096
16
+ curious_pyapi-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Child Mind Institute — Research Teams
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.