Skip to content

Commit ff1aee8

Browse files
committed
Merge branch 'main' into stable
2 parents c632352 + e47c822 commit ff1aee8

File tree

8 files changed

+64
-47
lines changed

8 files changed

+64
-47
lines changed

docs/guides/nodeinfo.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ builder.set_software(
2525
)
2626

2727
# 3. Define supported protocols
28-
builder.set_protocols([Protocol.ACTIVITYPUB])
28+
builder.set_protocols(["activitypub"])
2929

3030
# 4. Specify inbound and outbound services
3131
builder.set_services(
3232
inbound=["atom1.0", "rss2.0"],
33-
outbound=[Outbound.MASTODON, "twitter"]
33+
outbound=["twitter"]
3434
)
3535

3636
# 5. Set user statistics
@@ -77,11 +77,11 @@ try:
7777
homepage="https://maws.example.com"
7878
)
7979
# 3. Define supported protocols
80-
.set_protocols([Protocol.ACTIVITYPUB])
80+
.set_protocols(["activitypub"])
8181
# 4. Specify inbound and outbound services
8282
.set_services(
8383
inbound=["atom1.0", "rss2.0"],
84-
outbound=[Outbound.MASTODON, "twitter"]
84+
outbound=["twitter"]
8585
)
8686
# 5. Set user statistics
8787
.set_usage(
@@ -108,7 +108,7 @@ except (ValueError, TypeError) as e:
108108

109109
- **`__init__(version="2.1")`**: Creates a new builder instance. Accepts `"2.1"` or `"2.0"`.
110110
- **`set_software(...)`**: Sets the server's software details. `name` and `version` are required.
111-
- **`set_protocols(...)`**: Defines the protocols the server supports, like `Protocol.ACTIVITYPUB`.
111+
- **`set_protocols(...)`**: Defines the protocols the server supports, like `activitypub`.
112112
- **`set_services(...)`**: Lists the inbound and outbound services the server can connect to.
113113
- **`set_usage(...)`**: Provides user and content statistics. `users_total` is required.
114114
- **`set_open_registrations(...)`**: A boolean indicating if new user registrations are open. This is required.
@@ -137,7 +137,6 @@ The example above would produce the following JSON output:
137137
"rss2.0"
138138
],
139139
"outbound": [
140-
"mastodon",
141140
"twitter"
142141
]
143142
},

examples/delete.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import asyncio
22
import logging
33
import os
4-
import uuid
54
import sys
5+
import uuid
6+
from datetime import UTC, datetime
67

7-
from apkit.client.asyncio import ActivityPubClient
8-
from apkit.models import Person, CryptographicKey, Delete
9-
from cryptography.hazmat.primitives.asymmetric import rsa
108
from cryptography.hazmat.primitives import serialization as crypto_serialization
11-
from datetime import datetime, UTC
9+
from cryptography.hazmat.primitives.asymmetric import rsa
10+
11+
from apkit.client.asyncio import ActivityPubClient
12+
from apkit.models import CryptographicKey, Delete, Person
1213

1314
if len(sys.argv) < 3:
1415
print("USAGE: python delete.py <RECEPIENT_URI> <OBJECT_ID>", file=sys.stderr)
@@ -65,14 +66,14 @@
6566
actor = Person(
6667
id=f"https://{HOST}/users/{USER_ID}",
6768
name="apkit Demo",
68-
preferredUsername="demo",
69+
preferred_username="demo",
6970
summary="This is a demo actor powered by apkit!",
7071
inbox=f"https://{HOST}/users/{USER_ID}/inbox",
7172
outbox=f"https://{HOST}/users/{USER_ID}/outbox",
72-
publicKey=CryptographicKey(
73+
public_key=CryptographicKey(
7374
id=f"https://{HOST}/users/{USER_ID}#main-key",
7475
owner=f"https://{HOST}/users/{USER_ID}",
75-
publicKeyPem=public_key_pem,
76+
public_key_pem=public_key_pem,
7677
),
7778
)
7879

@@ -104,7 +105,10 @@ async def delete_note(recepient: str, object_id: str) -> None:
104105
logger.info("Delivering activity...")
105106

106107
resp = await client.post(
107-
inbox_url, key_id=actor.publicKey.id, signature=private_key, json=delete
108+
inbox_url,
109+
key_id=actor.publicKey.id,
110+
signature=private_key,
111+
json=delete,
108112
)
109113
logger.info(f"Delivery result: {resp.status}")
110114

examples/follow.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import asyncio
22
import logging
33
import os
4-
import uuid
54
import sys
5+
import uuid
66

7-
from apkit.client.asyncio import ActivityPubClient
8-
from apkit.models import Person, CryptographicKey, Follow
9-
from cryptography.hazmat.primitives.asymmetric import rsa
107
from cryptography.hazmat.primitives import serialization as crypto_serialization
8+
from cryptography.hazmat.primitives.asymmetric import rsa
9+
10+
from apkit.client.asyncio import ActivityPubClient
1111
from apkit.client.models import Resource as WebfingerResource
12+
from apkit.models import CryptographicKey, Follow, Person
1213

1314
if len(sys.argv) < 2:
1415
print("USAGE: python follow.py <ACTOR_ID>", file=sys.stderr)
@@ -65,14 +66,14 @@
6566
actor = Person(
6667
id=f"https://{HOST}/users/{USER_ID}",
6768
name="apkit Demo",
68-
preferredUsername="demo",
69+
preferred_username="demo",
6970
summary="This is a demo actor powered by apkit!",
7071
inbox=f"https://{HOST}/users/{USER_ID}/inbox",
7172
outbox=f"https://{HOST}/users/{USER_ID}/outbox",
72-
publicKey=CryptographicKey(
73+
public_key_pem=CryptographicKey(
7374
id=f"https://{HOST}/users/{USER_ID}#main-key",
7475
owner=f"https://{HOST}/users/{USER_ID}",
75-
publicKeyPem=public_key_pem,
76+
public_key=public_key_pem,
7677
),
7778
)
7879

@@ -113,7 +114,10 @@ async def follow(actor_id: str) -> None:
113114
logger.info("Delivering activity...")
114115

115116
resp = await client.post(
116-
inbox_url, key_id=actor.publicKey.id, signature=private_key, json=activity
117+
inbox_url,
118+
key_id=actor.public_key.id,
119+
signature=private_key,
120+
json=activity,
117121
)
118122
logger.info(f"Delivery result: {resp.status}")
119123
logger.info(f"To undo this action, use this URI: {activity.id}")

examples/like.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import asyncio
22
import logging
33
import os
4-
import uuid
54
import sys
5+
import uuid
6+
from datetime import UTC, datetime
67

7-
from apkit.client.asyncio import ActivityPubClient
8-
from apkit.models import Person, CryptographicKey, Like
9-
from cryptography.hazmat.primitives.asymmetric import rsa
108
from cryptography.hazmat.primitives import serialization as crypto_serialization
11-
from datetime import datetime, UTC
9+
from cryptography.hazmat.primitives.asymmetric import rsa
10+
11+
from apkit.client.asyncio import ActivityPubClient
12+
from apkit.models import CryptographicKey, Like, Person
1213

1314
if len(sys.argv) < 2:
1415
print("USAGE: python like.py <OBJECT_ID>", file=sys.stderr)
@@ -65,14 +66,14 @@
6566
actor = Person(
6667
id=f"https://{HOST}/users/{USER_ID}",
6768
name="apkit Demo",
68-
preferredUsername="demo",
69+
preferred_username="demo",
6970
summary="This is a demo actor powered by apkit!",
7071
inbox=f"https://{HOST}/users/{USER_ID}/inbox",
7172
outbox=f"https://{HOST}/users/{USER_ID}/outbox",
72-
publicKey=CryptographicKey(
73+
public_key=CryptographicKey(
7374
id=f"https://{HOST}/users/{USER_ID}#main-key",
7475
owner=f"https://{HOST}/users/{USER_ID}",
75-
publicKeyPem=public_key_pem,
76+
public_key_pem=public_key_pem,
7677
),
7778
)
7879

@@ -109,7 +110,10 @@ async def like(object_id: str) -> None:
109110
logger.info("Delivering activity...")
110111

111112
resp = await client.post(
112-
inbox_url, key_id=actor.publicKey.id, signature=private_key, json=activity
113+
inbox_url,
114+
key_id=actor.publicKey.id,
115+
signature=private_key,
116+
json=activity,
113117
)
114118
logger.info(f"Delivery result: {resp.status}")
115119
logger.info(f"To undo this action, use this URI: {activity.id}")

examples/minimal_server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
CryptographicKey,
1818
Follow,
1919
Nodeinfo,
20-
NodeinfoProtocol,
2120
NodeinfoServices,
2221
NodeinfoSoftware,
2322
NodeinfoUsage,
@@ -160,9 +159,9 @@ async def nodeinfo_endpoint():
160159
Nodeinfo(
161160
version="2.1",
162161
software=NodeinfoSoftware(name="apkit-demo", version="0.1.0"),
163-
protocols=[NodeinfoProtocol.ACTIVITYPUB],
162+
protocols=["activitypub"],
164163
services=NodeinfoServices(inbound=[], outbound=[]),
165-
openRegistrations=False,
164+
open_registrations=False,
166165
usage=NodeinfoUsage(users=NodeinfoUsageUsers(total=1)),
167166
metadata={},
168167
)

examples/send_message.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import asyncio
22
import logging
33
import os
4-
import uuid
54
import sys
5+
import uuid
6+
from datetime import UTC, datetime
67

7-
from apkit.client.asyncio import ActivityPubClient
8-
from apkit.models import Person, Note, CryptographicKey, Create
9-
from cryptography.hazmat.primitives.asymmetric import rsa
108
from cryptography.hazmat.primitives import serialization as crypto_serialization
11-
from datetime import datetime, UTC
9+
from cryptography.hazmat.primitives.asymmetric import rsa
10+
11+
from apkit.client.asyncio import ActivityPubClient
1212
from apkit.client.models import Resource as WebfingerResource
13+
from apkit.models import Create, CryptographicKey, Note, Person
1314

1415
if len(sys.argv) < 2:
1516
print("USAGE: python send_message.py <RECEPIENT_URI>", file=sys.stderr)
@@ -66,14 +67,14 @@
6667
actor = Person(
6768
id=f"https://{HOST}/users/{USER_ID}",
6869
name="apkit Demo",
69-
preferredUsername="demo",
70+
preferred_username="demo",
7071
summary="This is a demo actor powered by apkit!",
7172
inbox=f"https://{HOST}/users/{USER_ID}/inbox",
7273
outbox=f"https://{HOST}/users/{USER_ID}/outbox",
73-
publicKey=CryptographicKey(
74+
public_key=CryptographicKey(
7475
id=f"https://{HOST}/users/{USER_ID}#main-key",
7576
owner=f"https://{HOST}/users/{USER_ID}",
76-
publicKeyPem=public_key_pem,
77+
public_key_pem=public_key_pem,
7778
),
7879
)
7980

@@ -107,7 +108,7 @@ async def send_note(recepient: str) -> None:
107108
# Create note
108109
note = Note(
109110
id=f"https://{HOST}/notes/{uuid.uuid4()}",
110-
attributedTo=actor.id,
111+
attributed_to=actor.id,
111112
content="<p>Hello from apkit</p>",
112113
published=datetime.now(UTC).isoformat() + "Z",
113114
to=[target_actor.id],

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nav:
1313
- Server: guides/server.md
1414
- Models: guides/models.md
1515
- KV Store: guides/kv_store.md
16+
- Nodeinfo: guides/nodeinfo.md
1617
- Advanced:
1718
- Overview: guides/advanced/index.md
1819
- Framework Integration: guides/advanced/framework_integration.md

src/apkit/server/responses.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Mapping
22

33
import apmodel
4+
from apmodel.nodeinfo.nodeinfo import Nodeinfo
45
from apmodel.types import ActivityPubModel
56
from fastapi.responses import JSONResponse
67
from starlette.background import BackgroundTask
@@ -11,13 +12,17 @@ class ActivityResponse(JSONResponse):
1112

1213
def __init__(
1314
self,
14-
content: ActivityPubModel,
15+
content: ActivityPubModel | Nodeinfo,
1516
status_code: int = 200,
1617
headers: Mapping[str, str] | None = None,
1718
media_type: str | None = None,
1819
background: BackgroundTask | None = None,
1920
) -> None:
2021
super().__init__(content, status_code, headers, media_type, background)
2122

22-
def render(self, content: ActivityPubModel) -> bytes:
23-
return super().render(apmodel.to_dict(content))
23+
def render(self, content: ActivityPubModel | Nodeinfo) -> bytes:
24+
if isinstance(content, ActivityPubModel):
25+
rendered = apmodel.to_dict(content)
26+
else:
27+
rendered = content.model_dump()
28+
return super().render(rendered)

0 commit comments

Comments
 (0)