longwei 1.0.0.dev0__tar.gz → 1.1.1__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: longwei
3
- Version: 1.0.0.dev0
3
+ Version: 1.1.1
4
4
  Summary: Python client library for ActivityPub-compatible servers
5
5
  Author: marvin8
6
6
  Author-email: marvin8 <marvin8@tuta.io>
@@ -16,17 +16,16 @@ Classifier: Programming Language :: Python :: 3.14
16
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
17
  Requires-Dist: httpx[http2,zstd]~=0.28.1
18
18
  Requires-Dist: pydantic~=2.12.5
19
- Requires-Dist: pytz~=2026.1.post1
20
- Requires-Dist: whenever~=0.9.5
21
19
  Requires-Python: >=3.11, <3.15
22
- Project-URL: Changelog, https://codeberg.org/MarvinsMastodonTools/longwei/src/branch/main/CHANGELOG.md
23
- Project-URL: Documentation, https://marvinsmastodontools.codeberg.page/longwei/
20
+ Project-URL: Documentation, https://marvinsmastodontools.codeberg.page/longwei/latest/
24
21
  Project-URL: Issues, https://codeberg.org/MarvinsMastodonTools/longwei/issues
25
22
  Project-URL: Source, https://codeberg.org/MarvinsMastodonTools/longwei
23
+ Project-URL: Changelog, https://codeberg.org/MarvinsMastodonTools/longwei/src/branch/main/CHANGELOG.md
26
24
  Description-Content-Type: text/markdown
27
25
 
28
26
  # longwei
29
27
 
28
+ [![Docs](https://img.shields.io/badge/docs-latest-blue)](https://marvinsmastodontools.codeberg.page/longwei/latest/ "Latest documentation")
30
29
  [![Repo](https://img.shields.io/badge/repo-Codeberg.org-blue)](https://codeberg.org/MarvinsMastodonTools/longwei "Repo at Codeberg.org")
31
30
  [![CI](https://ci.codeberg.org/api/badges/MarvinsMastodonTools/longwei/status.svg)](https://ci.codeberg.org/MarvinsMastodonTools/longwei "CI / Woodpecker")
32
31
  [![Downloads](https://pepy.tech/badge/longwei)](https://pepy.tech/project/longwei "Download count")
@@ -39,25 +38,48 @@ Description-Content-Type: text/markdown
39
38
  [![Wheel](https://img.shields.io/pypi/wheel/longwei)](https://pypi.org/project/longwei "PyPI – Wheel")
40
39
  [![License: AGPL-3.0-or-later](https://img.shields.io/badge/License-AGPL--3.0--or--later-blue.svg)](https://spdx.org/licenses/AGPL-3.0-or-later.html "AGPL 3 or later")
41
40
 
42
- Longwei is a minimal Python implementation of the ActivityPub REST API used by [Mastodon](https://joinmastodon.org/), [Pleroma](https://pleroma.social/), [GotoSocial](https://gotosocial.org/), and [Takahe](https://jointakahe.org/). This implementation makes use of asyncio where appropriate. It is intended to be used as a library by other applications. No standalone functionality is provided.
41
+ Longwei is a minimal Python implementation of the ActivityPub client REST API used by [Mastodon](https://joinmastodon.org/), [Pleroma](https://pleroma.social/), and [GotoSocial](https://gotosocial.org/). This implementation makes use of asyncio where appropriate. It is intended to be used as a library by other applications. No standalone functionality is provided.
43
42
 
44
- So far Longwei only implements the activtiy pub API calls I need for my other projects [Fedinesia](https://codeberg.org/MarvinsMastodonTools/fedinesia), [Feed2Fedi](https://codeberg.org/marvinsmastodontools/feed2fedi), [FenLiu and Zhongli](https://codeberg.org/marvinsmastodontools/dujiangyan).
43
+ So far Longwei only implements the ActivityPub API calls I need for my other projects [Fedinesia](https://codeberg.org/MarvinsMastodonTools/fedinesia), [Feed2Fedi](https://codeberg.org/marvinsmastodontools/feed2fedi), [FenLiu and Zhongli](https://codeberg.org/marvinsmastodontools/dujiangyan).
45
44
 
46
45
  **DO NOT** expect a full or complete implementation of all [ActivityPub API](https://activitypub.rocks/) functionality.
47
46
 
47
+ ## Quick start
48
+
49
+ ```bash
50
+ pip install longwei
51
+ ```
52
+
53
+ ```python
54
+ import asyncio
55
+ import httpx
56
+ from longwei import APClient
57
+
58
+ async def main():
59
+ async with httpx.AsyncClient() as client:
60
+ ap = await APClient.create(
61
+ instance="mastodon.social",
62
+ client=client,
63
+ access_token="your_token",
64
+ )
65
+ status = await ap.post_status("Hello, fediverse!")
66
+ print(status.url)
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
48
71
  ## API References
49
72
 
50
73
  - [Mastodon API](https://docs.joinmastodon.org/api/)
51
74
  - [Pleroma API](https://api.pleroma.social)
52
75
  - [GotoSocial API](https://docs.gotosocial.org/en/stable/api/swagger/)
53
76
 
54
- ## Heavy Development / Breaking Changes
55
-
56
- I have only just forked this from minimal_activitypub and am still working on it. Expect some major changes still and some breaking changes.
57
- It is **not** a drop in replacement and will need some adjustments, even when I am done with the rework.
77
+ ## Status
58
78
 
59
- I advise not to use this at until at least version 1.0.0 (non dev)
79
+ longwei is a fork of `minimal_activitypub`. The main breaking change from that package is the
80
+ class rename: `ActivityPub` → `APClient`. See the [Upgrading guide](https://marvinsmastodontools.codeberg.page/longwei/latest/upgrading/) for migration instructions.
60
81
 
82
+ It is **not** a drop-in replacement. See the upgrading guide for migration instructions.
61
83
 
62
84
  ## Contributing
63
85
 
@@ -67,26 +89,15 @@ longwei is using [pre-commit](https://pre-commit.com/) for code quality checks a
67
89
 
68
90
  ## Documentation
69
91
 
70
- The documentation is built using [MkDocs](https://www.mkdocs.org/) with the [Material theme](https://squidfunk.github.io/mkdocs-material/).
92
+ The live documentation is at **https://marvinsmastodontools.codeberg.page/longwei/latest/**
71
93
 
72
- ### Building Documentation Locally
94
+ Built with [MkDocs](https://www.mkdocs.org/) and the [Material theme](https://squidfunk.github.io/mkdocs-material/). To build and serve locally:
73
95
 
74
96
  ```bash
75
- # Install documentation dependencies (using the docs group from pyproject.toml)
76
97
  uv sync --group docs
77
-
78
- # Build documentation
79
- mkdocs build
80
-
81
- # Serve documentation locally
82
98
  mkdocs serve
83
99
  ```
84
100
 
85
- ### Documentation Structure
86
-
87
- - `docs/` - Markdown source files
88
- - `mkdocs.yml` - MkDocs configuration
89
-
90
101
  ## Development
91
102
 
92
103
  This project uses [uv](https://docs.astral.sh/uv/) for dependency management and virtual environments. To set up the development environment:
@@ -1,5 +1,6 @@
1
1
  # longwei
2
2
 
3
+ [![Docs](https://img.shields.io/badge/docs-latest-blue)](https://marvinsmastodontools.codeberg.page/longwei/latest/ "Latest documentation")
3
4
  [![Repo](https://img.shields.io/badge/repo-Codeberg.org-blue)](https://codeberg.org/MarvinsMastodonTools/longwei "Repo at Codeberg.org")
4
5
  [![CI](https://ci.codeberg.org/api/badges/MarvinsMastodonTools/longwei/status.svg)](https://ci.codeberg.org/MarvinsMastodonTools/longwei "CI / Woodpecker")
5
6
  [![Downloads](https://pepy.tech/badge/longwei)](https://pepy.tech/project/longwei "Download count")
@@ -12,25 +13,48 @@
12
13
  [![Wheel](https://img.shields.io/pypi/wheel/longwei)](https://pypi.org/project/longwei "PyPI – Wheel")
13
14
  [![License: AGPL-3.0-or-later](https://img.shields.io/badge/License-AGPL--3.0--or--later-blue.svg)](https://spdx.org/licenses/AGPL-3.0-or-later.html "AGPL 3 or later")
14
15
 
15
- Longwei is a minimal Python implementation of the ActivityPub REST API used by [Mastodon](https://joinmastodon.org/), [Pleroma](https://pleroma.social/), [GotoSocial](https://gotosocial.org/), and [Takahe](https://jointakahe.org/). This implementation makes use of asyncio where appropriate. It is intended to be used as a library by other applications. No standalone functionality is provided.
16
+ Longwei is a minimal Python implementation of the ActivityPub client REST API used by [Mastodon](https://joinmastodon.org/), [Pleroma](https://pleroma.social/), and [GotoSocial](https://gotosocial.org/). This implementation makes use of asyncio where appropriate. It is intended to be used as a library by other applications. No standalone functionality is provided.
16
17
 
17
- So far Longwei only implements the activtiy pub API calls I need for my other projects [Fedinesia](https://codeberg.org/MarvinsMastodonTools/fedinesia), [Feed2Fedi](https://codeberg.org/marvinsmastodontools/feed2fedi), [FenLiu and Zhongli](https://codeberg.org/marvinsmastodontools/dujiangyan).
18
+ So far Longwei only implements the ActivityPub API calls I need for my other projects [Fedinesia](https://codeberg.org/MarvinsMastodonTools/fedinesia), [Feed2Fedi](https://codeberg.org/marvinsmastodontools/feed2fedi), [FenLiu and Zhongli](https://codeberg.org/marvinsmastodontools/dujiangyan).
18
19
 
19
20
  **DO NOT** expect a full or complete implementation of all [ActivityPub API](https://activitypub.rocks/) functionality.
20
21
 
22
+ ## Quick start
23
+
24
+ ```bash
25
+ pip install longwei
26
+ ```
27
+
28
+ ```python
29
+ import asyncio
30
+ import httpx
31
+ from longwei import APClient
32
+
33
+ async def main():
34
+ async with httpx.AsyncClient() as client:
35
+ ap = await APClient.create(
36
+ instance="mastodon.social",
37
+ client=client,
38
+ access_token="your_token",
39
+ )
40
+ status = await ap.post_status("Hello, fediverse!")
41
+ print(status.url)
42
+
43
+ asyncio.run(main())
44
+ ```
45
+
21
46
  ## API References
22
47
 
23
48
  - [Mastodon API](https://docs.joinmastodon.org/api/)
24
49
  - [Pleroma API](https://api.pleroma.social)
25
50
  - [GotoSocial API](https://docs.gotosocial.org/en/stable/api/swagger/)
26
51
 
27
- ## Heavy Development / Breaking Changes
52
+ ## Status
28
53
 
29
- I have only just forked this from minimal_activitypub and am still working on it. Expect some major changes still and some breaking changes.
30
- It is **not** a drop in replacement and will need some adjustments, even when I am done with the rework.
31
-
32
- I advise not to use this at until at least version 1.0.0 (non dev)
54
+ longwei is a fork of `minimal_activitypub`. The main breaking change from that package is the
55
+ class rename: `ActivityPub` `APClient`. See the [Upgrading guide](https://marvinsmastodontools.codeberg.page/longwei/latest/upgrading/) for migration instructions.
33
56
 
57
+ It is **not** a drop-in replacement. See the upgrading guide for migration instructions.
34
58
 
35
59
  ## Contributing
36
60
 
@@ -40,26 +64,15 @@ longwei is using [pre-commit](https://pre-commit.com/) for code quality checks a
40
64
 
41
65
  ## Documentation
42
66
 
43
- The documentation is built using [MkDocs](https://www.mkdocs.org/) with the [Material theme](https://squidfunk.github.io/mkdocs-material/).
67
+ The live documentation is at **https://marvinsmastodontools.codeberg.page/longwei/latest/**
44
68
 
45
- ### Building Documentation Locally
69
+ Built with [MkDocs](https://www.mkdocs.org/) and the [Material theme](https://squidfunk.github.io/mkdocs-material/). To build and serve locally:
46
70
 
47
71
  ```bash
48
- # Install documentation dependencies (using the docs group from pyproject.toml)
49
72
  uv sync --group docs
50
-
51
- # Build documentation
52
- mkdocs build
53
-
54
- # Serve documentation locally
55
73
  mkdocs serve
56
74
  ```
57
75
 
58
- ### Documentation Structure
59
-
60
- - `docs/` - Markdown source files
61
- - `mkdocs.yml` - MkDocs configuration
62
-
63
76
  ## Development
64
77
 
65
78
  This project uses [uv](https://docs.astral.sh/uv/) for dependency management and virtual environments. To set up the development environment:
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["uv_build>=0.8.7,<0.9.0"]
2
+ requires = ["uv_build>=0.11.3,<0.12.0"]
3
3
  build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "longwei"
7
- version = "1.0.0dev0"
7
+ version = "1.1.1"
8
8
  authors = [
9
9
  { name = "marvin8", email = "marvin8@tuta.io" },
10
10
  ]
@@ -26,8 +26,6 @@ requires-python = ">=3.11, <3.15"
26
26
  dependencies = [
27
27
  "httpx[http2,zstd]~=0.28.1",
28
28
  "pydantic~=2.12.5",
29
- "pytz~=2026.1.post1",
30
- "whenever~=0.9.5",
31
29
  ]
32
30
  [dependency-groups]
33
31
  dev = [
@@ -35,15 +33,16 @@ dev = [
35
33
  "complexipy~=5.2.0",
36
34
  "git-cliff~=2.12.0",
37
35
  "prek~=0.3.8",
38
- "ruff~=0.15.8",
39
- "ty~=0.0.27",
40
- "uv~=0.11.2",
36
+ "ruff~=0.15.9",
37
+ "ty~=0.0.29",
38
+ "uv~=0.11.3",
41
39
  ]
42
40
  docs = [
43
- "mike~=2.1.4",
44
41
  "mkdocs~=1.6.1",
45
42
  "mkdocs-material~=9.7.6",
43
+ "mkdocstrings~=1.0.3",
46
44
  "mkdocstrings-python~=2.0.3",
45
+ "mike~=2.1.4",
47
46
  ]
48
47
  nox = [
49
48
  "nox-uv~=0.7.1",
@@ -61,7 +60,7 @@ constraint-dependencies = [
61
60
  ]
62
61
 
63
62
  [project.urls]
64
- Documentation = "https://marvinsmastodontools.codeberg.page/longwei/"
63
+ Documentation = "https://marvinsmastodontools.codeberg.page/longwei/latest/"
65
64
  Issues = "https://codeberg.org/MarvinsMastodonTools/longwei/issues"
66
65
  Source = "https://codeberg.org/MarvinsMastodonTools/longwei"
67
66
  Changelog = "https://codeberg.org/MarvinsMastodonTools/longwei/src/branch/main/CHANGELOG.md"
@@ -1,49 +1,45 @@
1
- """Simplifies interacting with an ActivityPub server / instance.
2
-
3
- This is a minimal implementation only implementing some API calls. API
4
- calls supported will likely be expanded over time. However, do not
5
- expect a full or complete implementation of the ActivityPub API.
6
- """
1
+ """Package 'longwei' level definitions."""
7
2
 
8
3
  import logging
4
+ from datetime import UTC
5
+ from datetime import datetime
9
6
 
10
7
  from httpx import AsyncClient
11
- from whenever import Instant
12
8
 
13
- from longwei import SearchType # noqa: F401
14
- from longwei import Visibility # noqa: F401
15
- from longwei import __display_name__
16
- from longwei import __version__
9
+ from longwei._base import USER_AGENT
10
+ from longwei._base import __display_name__
11
+ from longwei._base import __version__
17
12
  from longwei._mixin_auth import _AuthMixin
18
13
  from longwei._mixin_credentials import _CredentialsMixin
19
14
  from longwei._mixin_request_helpers import _RequestHelpersMixin
20
15
  from longwei._mixin_statuses import _StatusesMixin
21
16
  from longwei._mixin_timelines import _TimelinesMixin
22
17
  from longwei.constants import INSTANCE_TYPE_MASTODON
23
- from longwei.constants import INSTANCE_TYPE_PLEROMA # noqa: F401
24
- from longwei.constants import INSTANCE_TYPE_TAKAHE # noqa: F401
18
+ from longwei.constants import INSTANCE_TYPE_PLEROMA
25
19
  from longwei.constants import MAX_ATTACHMENTS_MASTODON
26
- from longwei.constants import MAX_ATTACHMENTS_PLEROMA # noqa: F401
27
- from longwei.constants import MAX_ATTACHMENTS_TAKAHE # noqa: F401
28
- from longwei.exceptions import ActivityPubError # noqa: F401
29
- from longwei.exceptions import ApiError # noqa: F401
30
- from longwei.exceptions import ClientError # noqa: F401
31
- from longwei.exceptions import ConflictError # noqa: F401
32
- from longwei.exceptions import ForbiddenError # noqa: F401
33
- from longwei.exceptions import GoneError # noqa: F401
34
- from longwei.exceptions import NetworkError # noqa: F401
35
- from longwei.exceptions import NotFoundError # noqa: F401
36
- from longwei.exceptions import RatelimitError # noqa: F401
37
- from longwei.exceptions import ServerError # noqa: F401
38
- from longwei.exceptions import UnauthorizedError # noqa: F401
39
- from longwei.exceptions import UnprocessedError # noqa: F401
40
- from longwei.types import ActivityPubClass
41
- from longwei.types import Status # noqa: F401
20
+ from longwei.enums import SearchType
21
+ from longwei.enums import Visibility
22
+ from longwei.exceptions import ActivityPubError
23
+ from longwei.exceptions import ApiError
24
+ from longwei.exceptions import ClientError
25
+ from longwei.exceptions import ConflictError
26
+ from longwei.exceptions import ForbiddenError
27
+ from longwei.exceptions import GoneError
28
+ from longwei.exceptions import NetworkError
29
+ from longwei.exceptions import NotFoundError
30
+ from longwei.exceptions import RatelimitError
31
+ from longwei.exceptions import ServerError
32
+ from longwei.exceptions import UnauthorizedError
33
+ from longwei.exceptions import UnprocessedError
34
+ from longwei.models import Account
35
+ from longwei.models import SearchResults
36
+ from longwei.types import APClientClass
37
+ from longwei.types import Status
42
38
 
43
39
  logger = logging.getLogger(__display_name__)
44
40
 
45
41
 
46
- class ActivityPub(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _StatusesMixin, _AuthMixin):
42
+ class APClient(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _StatusesMixin, _AuthMixin):
47
43
  """Simplifies interacting with an ActivityPub server / instance.
48
44
 
49
45
  This is a minimal implementation only implementing methods needed
@@ -51,13 +47,13 @@ class ActivityPub(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _Sta
51
47
  """
52
48
 
53
49
  def __init__(
54
- self: ActivityPubClass,
50
+ self: APClientClass,
55
51
  instance: str,
56
52
  client: AsyncClient,
57
53
  access_token: str | None = None,
58
54
  timeout: int | None = None,
59
55
  ) -> None:
60
- """Initialise ActivityPub instance with reasonable default values.
56
+ """Initialise APClient instance with reasonable default values.
61
57
 
62
58
  :param instance: domain name or url to instance to connect to
63
59
  :param client: httpx AsyncClient to use for communicating with instance
@@ -83,13 +79,13 @@ class ActivityPub(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _Sta
83
79
  self.max_status_len = 500
84
80
  self.ratelimit_limit = 300
85
81
  self.ratelimit_remaining = 300
86
- self.ratelimit_reset = Instant.now().py_datetime()
82
+ self.ratelimit_reset = datetime.now(UTC)
87
83
  logger.debug(
88
- "client_2_server.ActivityPub(instance=%s, client=%s, access_token=<redacted>)",
84
+ "APClient(instance=%s, client=%s, access_token=<redacted>)",
89
85
  instance,
90
86
  client,
91
87
  )
92
- logger.debug("client_2_server.ActivityPub() ... version=%s", __version__)
88
+ logger.debug("APClient() ... version=%s", __version__)
93
89
 
94
90
  @classmethod
95
91
  async def create(
@@ -98,8 +94,8 @@ class ActivityPub(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _Sta
98
94
  client: AsyncClient,
99
95
  access_token: str | None = None,
100
96
  timeout: int | None = None,
101
- ) -> "ActivityPub":
102
- """Create and initialise an ActivityPub instance, auto-detecting the instance type.
97
+ ) -> "APClient":
98
+ """Create and initialise an APClient instance, auto-detecting the instance type.
103
99
 
104
100
  This is the recommended entry point. Unlike direct instantiation, this factory
105
101
  automatically calls :meth:`determine_instance_type` to configure server-specific
@@ -109,9 +105,37 @@ class ActivityPub(_RequestHelpersMixin, _CredentialsMixin, _TimelinesMixin, _Sta
109
105
  :param client: httpx AsyncClient to use for communicating with instance
110
106
  :param access_token: authentication token
111
107
  :param timeout: optional seconds to wait for a response (default: 120)
112
- :returns: Fully initialised :class:`ActivityPub` instance
108
+ :returns: Fully initialised :class:`APClient` instance
113
109
  :raises NetworkError: if the instance cannot be reached during type detection
114
110
  """
115
111
  ap = cls(instance=instance, client=client, access_token=access_token, timeout=timeout)
116
112
  await ap.determine_instance_type()
117
113
  return ap
114
+
115
+
116
+ __all__ = [ # noqa: RUF022
117
+ "Account",
118
+ "APClient",
119
+ "APClientClass",
120
+ "ActivityPubError",
121
+ "ApiError",
122
+ "ClientError",
123
+ "ConflictError",
124
+ "__display_name__",
125
+ "ForbiddenError",
126
+ "GoneError",
127
+ "INSTANCE_TYPE_MASTODON",
128
+ "INSTANCE_TYPE_PLEROMA",
129
+ "NetworkError",
130
+ "NotFoundError",
131
+ "RatelimitError",
132
+ "SearchResults",
133
+ "SearchType",
134
+ "ServerError",
135
+ "Status",
136
+ "UnauthorizedError",
137
+ "UnprocessedError",
138
+ "USER_AGENT",
139
+ "__version__",
140
+ "Visibility",
141
+ ]
@@ -0,0 +1,16 @@
1
+ """Internal base definitions shared across mixin modules.
2
+
3
+ This module exists to break the circular import that would arise if mixins
4
+ imported directly from the ``longwei`` package: package-level constants live
5
+ here so that ``__init__.py`` can import both this module and the mixins
6
+ without a cycle.
7
+ """
8
+
9
+ import sys
10
+ from importlib.metadata import version
11
+ from typing import Final
12
+
13
+ __display_name__: Final[str] = "Longwei"
14
+ __version__: Final[str] = version("longwei")
15
+
16
+ USER_AGENT: Final[str] = f"{__display_name__}_v{__version__}_Python_{sys.version.split()[0]}"
@@ -7,8 +7,8 @@ from urllib.parse import urlencode
7
7
  from httpx import AsyncClient
8
8
  from httpx import HTTPError
9
9
 
10
- from longwei import USER_AGENT
11
- from longwei import __display_name__
10
+ from longwei._base import USER_AGENT
11
+ from longwei._base import __display_name__
12
12
  from longwei.constants import REDIRECT_URI
13
13
  from longwei.exceptions import NetworkError
14
14
  from longwei.utils import _check_exception
@@ -32,9 +32,14 @@ class _AuthMixin:
32
32
  :param user_agent: User agent identifier to use. Defaults to longwei related one.
33
33
 
34
34
  :returns: String containing URL to visit to get access token interactively from instance.
35
+
36
+ Note:
37
+ Constructs a URL for ``GET /oauth/authorize``
38
+ (Mastodon, Pleroma, GotoSocial). No HTTP request is made by this method.
39
+
35
40
  """
36
41
  logger.debug(
37
- "ActivityPub.get_auth_token_interactive(instance_url=%s, client=...,client_id=%s, user_agent=%s)",
42
+ "APClient.get_auth_token_interactive(instance_url=%s, client=...,client_id=%s, user_agent=%s)",
38
43
  instance_url,
39
44
  client_id,
40
45
  user_agent,
@@ -52,7 +57,7 @@ class _AuthMixin:
52
57
  )
53
58
  auth_url = f"{instance_url}/oauth/authorize?{url_params}"
54
59
  logger.debug(
55
- "ActivityPub.get_auth_token_interactive(...) -> %s",
60
+ "APClient.get_auth_token_interactive(...) -> %s",
56
61
  auth_url,
57
62
  )
58
63
 
@@ -75,9 +80,14 @@ class _AuthMixin:
75
80
  :param client_secret: client secret as returned by create_app method
76
81
 
77
82
  :returns: access token
83
+
84
+ Note:
85
+ Implements ``POST /oauth/token`` with ``grant_type=authorization_code``
86
+ (Mastodon, Pleroma, GotoSocial).
87
+
78
88
  """
79
89
  logger.debug(
80
- "ActivityPub.validate_authorization_code(authorization_code=%s, client_id=%s, client_secret=<redacted>)",
90
+ "APClient.validate_authorization_code(authorization_code=%s, client_id=%s, client_secret=<redacted>)",
81
91
  authorization_code,
82
92
  client_id,
83
93
  )
@@ -95,7 +105,7 @@ class _AuthMixin:
95
105
  try:
96
106
  response = await client.post(url=f"{instance_url}/oauth/token", data=data)
97
107
  logger.debug(
98
- "ActivityPub.validate_authorization_code - response:\n%s",
108
+ "APClient.validate_authorization_code - response:\n%s",
99
109
  response,
100
110
  )
101
111
  await _check_exception(response)
@@ -104,7 +114,7 @@ class _AuthMixin:
104
114
  raise NetworkError from error
105
115
 
106
116
  logger.debug(
107
- "ActivityPub.validate_authorization_code - response.json: \n%s",
117
+ "APClient.validate_authorization_code - response.json: \n%s",
108
118
  json.dumps(response_dict, indent=4),
109
119
  )
110
120
  return str(response_dict["access_token"])
@@ -128,9 +138,15 @@ class _AuthMixin:
128
138
  :param client_website: Link to site for user_agent. Defaults to link to longwei on Pypi.org
129
139
 
130
140
  :returns: The access token is being returned.
141
+
142
+ Note:
143
+ Implements ``POST /oauth/token`` with ``grant_type=password``
144
+ (Pleroma, GotoSocial). The password grant is not supported by most
145
+ Mastodon instances by default.
146
+
131
147
  """
132
148
  logger.debug(
133
- "ActivityPub.get_auth_token(instance_url=%s, username=%s, password=<redacted>, client=..., "
149
+ "APClient.get_auth_token(instance_url=%s, username=%s, password=<redacted>, client=..., "
134
150
  "user_agent=%s, client_website=%s)",
135
151
  instance_url,
136
152
  username,
@@ -159,14 +175,14 @@ class _AuthMixin:
159
175
 
160
176
  try:
161
177
  response = await client.post(url=f"{instance_url}/oauth/token", data=data)
162
- logger.debug("ActivityPub.get_auth_token - response:\n%s", response)
178
+ logger.debug("APClient.get_auth_token - response:\n%s", response)
163
179
  await _check_exception(response)
164
180
  response_dict = response.json()
165
181
  except HTTPError as error:
166
182
  raise NetworkError from error
167
183
 
168
184
  logger.debug(
169
- "ActivityPub.get_auth_token - response.json: \n%s",
185
+ "APClient.get_auth_token - response.json: \n%s",
170
186
  json.dumps(response_dict, indent=4),
171
187
  )
172
188
  return str(response_dict["access_token"])
@@ -186,9 +202,13 @@ class _AuthMixin:
186
202
  :param client_website: Link to site for user_agent. Defaults to link to longwei on Pypi.org
187
203
 
188
204
  :returns: tuple(client_id, client_secret)
205
+
206
+ Note:
207
+ Implements ``POST /api/v1/apps`` (Mastodon, Pleroma, GotoSocial).
208
+
189
209
  """
190
210
  logger.debug(
191
- "ActivityPub.create_app(instance_url=%s, client=..., user_agent=%s, client_website=%s)",
211
+ "APClient.create_app(instance_url=%s, client=..., user_agent=%s, client_website=%s)",
192
212
  instance_url,
193
213
  user_agent,
194
214
  client_website,
@@ -205,14 +225,14 @@ class _AuthMixin:
205
225
  }
206
226
  try:
207
227
  response = await client.post(url=f"{instance_url}/api/v1/apps", data=data)
208
- logger.debug("ActivityPub.create_app response: \n%s", response)
228
+ logger.debug("APClient.create_app response: \n%s", response)
209
229
  await _check_exception(response)
210
230
  response_dict = response.json()
211
231
  except HTTPError as error:
212
232
  raise NetworkError from error
213
233
 
214
234
  logger.debug(
215
- "ActivityPub.create_app response.json: \n%s",
235
+ "APClient.create_app response.json: \n%s",
216
236
  json.dumps(response_dict, indent=4),
217
237
  )
218
238
  return (response_dict["client_id"]), (response_dict["client_secret"])