Habiticalib 0.1.0a0__tar.gz → 0.1.0a2__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 (49) hide show
  1. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/labels.yml +8 -5
  2. habiticalib-0.1.0a2/.github/release-drafter.yml +94 -0
  3. habiticalib-0.1.0a2/PKG-INFO +98 -0
  4. habiticalib-0.1.0a2/README.md +79 -0
  5. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/pyproject.toml +2 -2
  6. habiticalib-0.1.0a2/src/habiticalib/__init__.py +69 -0
  7. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/const.py +2 -0
  8. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/exceptions.py +15 -1
  9. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/helpers.py +3 -4
  10. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/lib.py +47 -37
  11. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/types.py +15 -5
  12. habiticalib-0.1.0a2/tests/__snapshots__/test_avatar.ambr +28 -0
  13. habiticalib-0.1.0a2/tests/__snapshots__/test_user.ambr +4 -0
  14. habiticalib-0.1.0a2/tests/conftest.py +49 -0
  15. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/tests/fixtures/user.json +10 -5
  16. habiticalib-0.1.0a2/tests/fixtures/user_styles.json +57 -0
  17. habiticalib-0.1.0a2/tests/fixtures/user_styles_kickstarter.json +57 -0
  18. habiticalib-0.1.0a2/tests/fixtures/user_styles_seafoam.json +57 -0
  19. habiticalib-0.1.0a2/tests/fixtures/user_styles_shinySeed.json +57 -0
  20. habiticalib-0.1.0a2/tests/fixtures/user_styles_sleeping.json +57 -0
  21. habiticalib-0.1.0a2/tests/fixtures/user_styles_snowball.json +57 -0
  22. habiticalib-0.1.0a2/tests/fixtures/user_styles_spookySparkles.json +57 -0
  23. habiticalib-0.1.0a2/tests/fixtures/user_styles_with_chair.json +57 -0
  24. habiticalib-0.1.0a2/tests/test_avatar.py +100 -0
  25. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/tests/test_user.py +1 -3
  26. habiticalib-0.1.0a0/.github/release-drafter.yml +0 -39
  27. habiticalib-0.1.0a0/PKG-INFO +0 -92
  28. habiticalib-0.1.0a0/README.md +0 -73
  29. habiticalib-0.1.0a0/src/habiticalib/__init__.py +0 -12
  30. habiticalib-0.1.0a0/tests/__snapshots__/test_user.ambr +0 -4
  31. habiticalib-0.1.0a0/tests/conftest.py +0 -27
  32. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.cruft.json +0 -0
  33. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.editorconfig +0 -0
  34. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/FUNDING.yml +0 -0
  35. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/dependabot.yml +0 -0
  36. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/workflows/build.yml +0 -0
  37. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/workflows/documentation.yml +0 -0
  38. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/workflows/draft.yml +0 -0
  39. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.github/workflows/labeler.yml +0 -0
  40. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.gitignore +0 -0
  41. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.pre-commit-config.yaml +0 -0
  42. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/.vscode/settings.json +0 -0
  43. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/LICENSE +0 -0
  44. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/docs/index.md +0 -0
  45. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/docs/reference/habiticalib.md +0 -0
  46. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/mkdocs.yml +0 -0
  47. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/src/habiticalib/py.typed +0 -0
  48. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/tests/__init__.py +0 -0
  49. {habiticalib-0.1.0a0 → habiticalib-0.1.0a2}/tests/test_init.py +0 -0
@@ -25,9 +25,10 @@
25
25
  - name: duplicate
26
26
  description: This issue or pull request already exists
27
27
  color: cfd3d7
28
- - name: enhancement
28
+ - name: feature
29
29
  description: New feature or request
30
30
  color: a2eeef
31
+ from_name: enhancement
31
32
  - name: github_actions
32
33
  description: Pull requests that update Github_actions code
33
34
  color: "000000"
@@ -49,17 +50,19 @@
49
50
  - name: question
50
51
  description: Further information is requested
51
52
  color: d876e3
52
- - name: refactoring
53
- description: Refactoring
53
+ - name: code quality
54
+ description: Code quality improvements
54
55
  color: ef67c4
55
- - name: removal
56
+ from_name: refactor
57
+ - name: deprecation
56
58
  description: Removals and Deprecations
57
59
  color: 9ae7ea
60
+ from_name: removal
58
61
  - name: style
59
62
  description: Style
60
63
  color: c120e5
61
64
  - name: testing
62
- description: Testing
65
+ description: Pull request that adds tests
63
66
  color: b1fc6f
64
67
  - name: wontfix
65
68
  description: This will not be worked on
@@ -0,0 +1,94 @@
1
+ name-template: '$RESOLVED_VERSION'
2
+ tag-template: 'v$RESOLVED_VERSION'
3
+
4
+
5
+ categories:
6
+ - title: '⚠️ Breaking changes'
7
+ labels:
8
+ - 'breaking'
9
+ - title: '🚀 Features'
10
+ labels:
11
+ - 'feature'
12
+ - 'enhancement'
13
+ - title: '🐛 Bug Fixes'
14
+ labels:
15
+ - 'bug'
16
+ - title: '⏳ Deprecations'
17
+ labels:
18
+ - 'deprecation'
19
+ - title: '📃 Documentation'
20
+ labels:
21
+ - 'documentation'
22
+ - title: '🧩 Dependency Updates'
23
+ labels:
24
+ - 'dependencies'
25
+ - 'github_actions'
26
+ collapse-after: 5
27
+ - title: '🧰 Maintenance'
28
+ labels:
29
+ - 'perfomance'
30
+ - 'refactor'
31
+ - 'ci'
32
+ - 'build'
33
+ - title: '🔬 Other updates'
34
+ labels:
35
+ - 'style'
36
+ - 'testing'
37
+
38
+ autolabeler:
39
+ - label: 'feature'
40
+ title:
41
+ - '/adds/i'
42
+ - label: 'bug'
43
+ title:
44
+ - '/fix/i'
45
+ - label: 'code quality'
46
+ title:
47
+ - '/Refactor/i'
48
+ - label: 'testing'
49
+ title:
50
+ - '/test:/i'
51
+ files:
52
+ - 'test_*'
53
+ - 'conftest.py'
54
+ - label: 'documentation'
55
+ title:
56
+ - '/docs:/i'
57
+ files:
58
+ - '*.md'
59
+ - 'mkdocs.yml'
60
+ - label: 'ci'
61
+ title:
62
+ - '/ci:/i'
63
+ files:
64
+ - '.github/*'
65
+ - label: 'dependencies'
66
+ title:
67
+ - '/bump/i'
68
+ - label: 'deprecation'
69
+ title:
70
+ - '/Deprecate/i'
71
+
72
+ change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
73
+ change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
74
+ exclude-contributors:
75
+ - 'tr4nt0r'
76
+
77
+ version-resolver:
78
+ major:
79
+ labels:
80
+ - 'major'
81
+ minor:
82
+ labels:
83
+ - 'minor'
84
+ patch:
85
+ labels:
86
+ - 'patch'
87
+ default: patch
88
+
89
+ template: |
90
+ ## Changes
91
+
92
+ $CHANGES
93
+
94
+ Special thanks to: $CONTRIBUTORS
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.3
2
+ Name: Habiticalib
3
+ Version: 0.1.0a2
4
+ Summary: Asynchronous Python client library for the Habitica API
5
+ Project-URL: Documentation, https://tr4nt0r.github.io/habiticalib/
6
+ Project-URL: Source, https://github.com/tr4nt0r/habiticalib
7
+ Author-email: Manfred Dennerlein Rodelo <manfred@dennerlein.name>
8
+ License: MIT License
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Requires-Python: >=3.12
14
+ Requires-Dist: aiohttp~=3.9
15
+ Requires-Dist: mashumaro~=3.13
16
+ Requires-Dist: orjson~=3.10
17
+ Requires-Dist: pillow~=10.4
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Habiticalib
21
+
22
+ <p align="center">
23
+ <em>Modern asynchronous Python client library for the Habitica API</em>
24
+ </p>
25
+
26
+ [![build](https://github.com/tr4nt0r/habiticalib/workflows/Build/badge.svg)](https://github.com/tr4nt0r/habiticalib/actions)
27
+ [![codecov](https://codecov.io/gh/tr4nt0r/habiticalib/graph/badge.svg?token=iEsZ1Ktj7d)](https://codecov.io/gh/tr4nt0r/habiticalib)
28
+ [![PyPI version](https://badge.fury.io/py/habiticalib.svg)](https://badge.fury.io/py/habiticalib)
29
+
30
+ **Habiticalib** is a Python library for interacting with the [Habitica API](https://habitica.com). It provides an organized, typed interface to work with Habitica’s features, including tasks, user data, and avatars. The goal of this library is to simplify integration with Habitica.
31
+
32
+ ## Key features
33
+
34
+ - **Asynchronous**: The library is fully asynchronous, allowing non-blocking API calls.
35
+ - **Fully typed with Dataclasses**: The library is fully typed using Python `dataclasses`. It handles serialization with `mashumaro` and `orjson` for efficient conversion between Habitica API JSON data and Python objects.
36
+ - **Dynamic avatar image generation**: Habiticalib can fetch all necessary assets (like equipped items, pets, and mounts) and combine them into a single avatar image. This image can be saved to disk or returned as a byte buffer for further processing.
37
+ **Fetch user data**: Retrieve and manage user data such as stats, preferences, and items. User data is structured with dataclasses to make it easy to work with.
38
+ - **Task management**: Support for creating, updating, and retrieving Habitica tasks (to-dos, dailies, habits, rewards) is provided.
39
+ - **Task status updates**: The library allows updates for task statuses, habit scoring, and daily completion.
40
+ - **Tags**: Habiticalib supports the creation, updating and deletion of tags.
41
+ - **Stat allocation, class cystem and sleep**: The library offers methods for stat point allocation and switching between Habitica classes. It also provides the ability to disable the class system and pausing damage(resting in the inn)
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install habiticalib
47
+ ```
48
+
49
+ ## Getting started
50
+ Here’s an example to demonstrate basic usage:
51
+
52
+ ```python
53
+ import asyncio
54
+
55
+ from aiohttp import ClientSession
56
+
57
+ from habiticalib import Habitica, TaskType
58
+
59
+
60
+ async def main():
61
+ async with ClientSession() as session:
62
+ habitica = Habitica(session)
63
+
64
+ # Login to Habitica
65
+ habitica.login(username="your_username", password="your_password")
66
+
67
+ # Fetch user data
68
+ user_data = await habitica.user()
69
+ print(f"Your current health: {user_data.stats.hp}")
70
+
71
+ # Fetch all tasks (to-dos, dailies, habits, and rewards)
72
+ tasks = await habitica.get_tasks()
73
+ print("All tasks:")
74
+ for task in tasks:
75
+ print(f"- {task.text} (type: {task.type})")
76
+
77
+ # Fetch only to-dos
78
+ todos = await habitica.get_tasks(task_type=TaskType.TODO)
79
+ print("\nTo-Do tasks:")
80
+ for todo in todos:
81
+ print(f"- {todo.text} (due: {todo.date})")
82
+
83
+ # Fetch only dailies
84
+ dailies = await habitica.tasks(task_type=TaskType.DAILY)
85
+ print("\nDailies:")
86
+ for daily in dailies:
87
+ print(f"- {daily.text}")
88
+
89
+ asyncio.run(main())
90
+ ```
91
+
92
+ ## Documentation
93
+
94
+ For full documentation and detailed usage examples, please visit the [Habiticalib documentation](https://tr4nt0r.github.io/habiticalib/).
95
+
96
+ ## License
97
+
98
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,79 @@
1
+ # Habiticalib
2
+
3
+ <p align="center">
4
+ <em>Modern asynchronous Python client library for the Habitica API</em>
5
+ </p>
6
+
7
+ [![build](https://github.com/tr4nt0r/habiticalib/workflows/Build/badge.svg)](https://github.com/tr4nt0r/habiticalib/actions)
8
+ [![codecov](https://codecov.io/gh/tr4nt0r/habiticalib/graph/badge.svg?token=iEsZ1Ktj7d)](https://codecov.io/gh/tr4nt0r/habiticalib)
9
+ [![PyPI version](https://badge.fury.io/py/habiticalib.svg)](https://badge.fury.io/py/habiticalib)
10
+
11
+ **Habiticalib** is a Python library for interacting with the [Habitica API](https://habitica.com). It provides an organized, typed interface to work with Habitica’s features, including tasks, user data, and avatars. The goal of this library is to simplify integration with Habitica.
12
+
13
+ ## Key features
14
+
15
+ - **Asynchronous**: The library is fully asynchronous, allowing non-blocking API calls.
16
+ - **Fully typed with Dataclasses**: The library is fully typed using Python `dataclasses`. It handles serialization with `mashumaro` and `orjson` for efficient conversion between Habitica API JSON data and Python objects.
17
+ - **Dynamic avatar image generation**: Habiticalib can fetch all necessary assets (like equipped items, pets, and mounts) and combine them into a single avatar image. This image can be saved to disk or returned as a byte buffer for further processing.
18
+ **Fetch user data**: Retrieve and manage user data such as stats, preferences, and items. User data is structured with dataclasses to make it easy to work with.
19
+ - **Task management**: Support for creating, updating, and retrieving Habitica tasks (to-dos, dailies, habits, rewards) is provided.
20
+ - **Task status updates**: The library allows updates for task statuses, habit scoring, and daily completion.
21
+ - **Tags**: Habiticalib supports the creation, updating and deletion of tags.
22
+ - **Stat allocation, class cystem and sleep**: The library offers methods for stat point allocation and switching between Habitica classes. It also provides the ability to disable the class system and pausing damage(resting in the inn)
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install habiticalib
28
+ ```
29
+
30
+ ## Getting started
31
+ Here’s an example to demonstrate basic usage:
32
+
33
+ ```python
34
+ import asyncio
35
+
36
+ from aiohttp import ClientSession
37
+
38
+ from habiticalib import Habitica, TaskType
39
+
40
+
41
+ async def main():
42
+ async with ClientSession() as session:
43
+ habitica = Habitica(session)
44
+
45
+ # Login to Habitica
46
+ habitica.login(username="your_username", password="your_password")
47
+
48
+ # Fetch user data
49
+ user_data = await habitica.user()
50
+ print(f"Your current health: {user_data.stats.hp}")
51
+
52
+ # Fetch all tasks (to-dos, dailies, habits, and rewards)
53
+ tasks = await habitica.get_tasks()
54
+ print("All tasks:")
55
+ for task in tasks:
56
+ print(f"- {task.text} (type: {task.type})")
57
+
58
+ # Fetch only to-dos
59
+ todos = await habitica.get_tasks(task_type=TaskType.TODO)
60
+ print("\nTo-Do tasks:")
61
+ for todo in todos:
62
+ print(f"- {todo.text} (due: {todo.date})")
63
+
64
+ # Fetch only dailies
65
+ dailies = await habitica.tasks(task_type=TaskType.DAILY)
66
+ print("\nDailies:")
67
+ for daily in dailies:
68
+ print(f"- {daily.text}")
69
+
70
+ asyncio.run(main())
71
+ ```
72
+
73
+ ## Documentation
74
+
75
+ For full documentation and detailed usage examples, please visit the [Habiticalib documentation](https://tr4nt0r.github.io/habiticalib/).
76
+
77
+ ## License
78
+
79
+ This project is licensed under the terms of the MIT license.
@@ -25,7 +25,7 @@ max-complexity = 25
25
25
 
26
26
  [tool.ruff.lint.per-file-ignores]
27
27
  "types.py" = ["N815"]
28
- "tests/*" = ["SLF001", "S101"]
28
+ "tests/*" = ["SLF001", "S101", "ARG001"]
29
29
 
30
30
  [tool.pytest.ini_options]
31
31
  testpaths = ["tests"]
@@ -61,7 +61,7 @@ allow-direct-references = true
61
61
  [tool.hatch.version]
62
62
  source = "regex_commit"
63
63
  commit_extra_args = ["-e"]
64
- path = "src/habiticalib/__init__.py"
64
+ path = "src/habiticalib/const.py"
65
65
 
66
66
  [tool.hatch.envs.default]
67
67
  python = "3.12"
@@ -0,0 +1,69 @@
1
+ """Modern asynchronous Python client library for the Habitica API."""
2
+
3
+ from .const import ASSETS_URL, DEFAULT_URL, __version__
4
+ from .exceptions import (
5
+ BadRequestError,
6
+ HabiticaException,
7
+ NotAuthorizedError,
8
+ NotFoundError,
9
+ )
10
+ from .lib import Habitica
11
+ from .types import (
12
+ Attributes,
13
+ Class,
14
+ Direction,
15
+ Frequency,
16
+ HabiticaClassSystemResponse,
17
+ HabiticaErrorResponse,
18
+ HabiticaLoginResponse,
19
+ HabiticaResponse,
20
+ HabiticaScoreResponse,
21
+ HabiticaStatsResponse,
22
+ HabiticaTagResponse,
23
+ HabiticaTagsResponse,
24
+ HabiticaTaskOrderResponse,
25
+ HabiticaTaskResponse,
26
+ HabiticaTasksResponse,
27
+ HabiticaUserExport,
28
+ HabiticaUserResponse,
29
+ Language,
30
+ Skill,
31
+ Task,
32
+ TaskFilter,
33
+ TaskType,
34
+ UserStyles,
35
+ )
36
+
37
+ __all__ = [
38
+ "__version__",
39
+ "ASSETS_URL",
40
+ "Attributes",
41
+ "BadRequestError",
42
+ "Class",
43
+ "DEFAULT_URL",
44
+ "Direction",
45
+ "Frequency",
46
+ "Habitica",
47
+ "HabiticaClassSystemResponse",
48
+ "HabiticaErrorResponse",
49
+ "HabiticaException",
50
+ "HabiticaLoginResponse",
51
+ "HabiticaResponse",
52
+ "HabiticaScoreResponse",
53
+ "HabiticaStatsResponse",
54
+ "HabiticaTagResponse",
55
+ "HabiticaTagsResponse",
56
+ "HabiticaTaskOrderResponse",
57
+ "HabiticaTaskResponse",
58
+ "HabiticaTasksResponse",
59
+ "HabiticaUserExport",
60
+ "HabiticaUserResponse",
61
+ "Language",
62
+ "NotAuthorizedError",
63
+ "NotFoundError",
64
+ "Skill",
65
+ "Task",
66
+ "TaskFilter",
67
+ "TaskType",
68
+ "UserStyles",
69
+ ]
@@ -1,5 +1,7 @@
1
1
  """Constants for Habiticalib."""
2
2
 
3
+ __version__ = "0.1.0a2"
4
+
3
5
  DEFAULT_URL = "https://habitica.com/"
4
6
  ASSETS_URL = "https://habitica-assets.s3.amazonaws.com/mobileApp/images/"
5
7
 
@@ -2,15 +2,25 @@
2
2
 
3
3
  from typing import Self
4
4
 
5
+ from multidict import CIMultiDictProxy
6
+
5
7
  from habiticalib.types import HabiticaErrorResponse
6
8
 
7
9
 
8
10
  class HabiticaException(Exception): # noqa: N818
9
11
  """Base class for Habitica errors."""
10
12
 
11
- def __init__(self: Self, error: HabiticaErrorResponse) -> None:
13
+ def __init__(
14
+ self: Self,
15
+ error: HabiticaErrorResponse,
16
+ headers: CIMultiDictProxy,
17
+ ) -> None:
12
18
  """Initialize the Exception."""
13
19
  self.error = error
20
+ self.rate_limit = headers.get("x-ratelimit-limit")
21
+ self.rate_limit_remaining = headers.get("x-ratelimit-remaining")
22
+ self.rate_limit_reset = headers.get("x-ratelimit-reset")
23
+ self.retry_after = headers.get("retry-after")
14
24
 
15
25
  super().__init__(error.message)
16
26
 
@@ -25,3 +35,7 @@ class NotFoundError(HabiticaException):
25
35
 
26
36
  class BadRequestError(HabiticaException):
27
37
  """BadRequest error."""
38
+
39
+
40
+ class TooManyRequestsError(HabiticaException):
41
+ """TooManyRequests error."""
@@ -1,13 +1,12 @@
1
1
  """Helper functions for Habiticalib."""
2
2
 
3
3
  from dataclasses import asdict
4
- from importlib.metadata import version
5
4
  import platform
6
5
  import uuid
7
6
 
8
7
  import aiohttp
9
8
 
10
- from .const import DEVELOPER_ID
9
+ from .const import DEVELOPER_ID, __version__
11
10
  from .types import HabiticaUserResponse, UserData, UserStyles
12
11
 
13
12
 
@@ -58,7 +57,7 @@ def get_user_agent() -> str:
58
57
  os_info = f"{os_name} {os_release} ({os_version}); {arch}"
59
58
 
60
59
  return (
61
- f"Habiticalib/{version("habiticalib")} ({os_info}) "
60
+ f"Habiticalib/{__version__} ({os_info}) "
62
61
  f"aiohttp/{aiohttp.__version__} Python/{platform.python_version()} "
63
62
  " +https://github.com/tr4nt0r/habiticalib)"
64
63
  )
@@ -106,7 +105,7 @@ def get_x_client(x_client: str | None = None) -> str:
106
105
 
107
106
  return x_client
108
107
 
109
- return f"{DEVELOPER_ID} - Habiticalib/{version("habiticalib")}"
108
+ return f"{DEVELOPER_ID} - Habiticalib/{__version__}"
110
109
 
111
110
 
112
111
  def extract_user_styles(user_data: HabiticaUserResponse) -> UserStyles: