ActivityStreams 2.0 and nodeinfo 2.0/2.1 implementation for Python.
Project description
apmodel
apmodel is a Python library that provides model implementations for various decentralized social web protocols.
It is designed to easily parse and handle JSON data from sources like Mastodon, Misskey, and other Fediverse software.
Features
- Automatic Model Resolution: The
apmodel.loadfunction automatically deserializes a JSON object into the appropriate Python object by reading itstypefield. If no matching model is found, the original dictionary is returned. - Flexible Deserialization: Any properties in the JSON that do not have a corresponding field in the model are collected into an
model_extradictionary. This ensures no data is lost. - Type Hinting: Fully type-hinted for a better development experience and robust static analysis.
Installation
pip install apmodel
# uv
uv add apmodel
Usage
Here is a basic example of how to parse an ActivityStreams 2.0 Note object from a JSON string.
import apmodel
# Example JSON from a Fediverse server
json_data = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/users/alice/statuses/1",
"type": "Note",
"published": "2023-12-25T12:00:00Z",
"attributedTo": "https://example.com/users/alice",
"content": "<p>Hello, world!</p>",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/users/alice/followers"]
}
# Load the JSON into an apmodel object
obj = apmodel.load(json_data)
# Now you can access properties with type safety
if isinstance(obj, apmodel.vocab.Note):
print(f"Type: {obj.type}")
print(f"Content: {obj.content}")
print(f"Published: {obj.published}")
# >> Type: Note
# >> Content: <p>Hello, world!</p>
# >> Published: 2023-12-25 12:00:00+00:00
Documentation
https://fedi-libs.github.io/apmodel
Supported Specifications
apmodel provides models for the following specifications:
- Activity Streams 2.0: Core types like
Object,Activity,Collection, andLink. - Activity Vocabulary: All types.
- Security Vocabulary v1:
CryptographicKey(Key). - Controlled Identifiers v1.0:
MultikeyandDataIntegrityProof. - schema.org:
PropertyValue. - NodeInfo 2.0/2.1
- Litepub:
EmojiReact - Others:
EmojiandHashtag
Development
This project uses Task for running scripts. You need to install it first.
-
Setup dev environment:
task
-
Run tests with Pytest:
task test
-
Build packages for PyPI:
task build -
Development Document:
task docs:dev
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apmodel-0.5.4.tar.gz.
File metadata
- Download URL: apmodel-0.5.4.tar.gz
- Upload date:
- Size: 222.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
526a830fe10e3b2b6ba18ddb390e04ecd5d77490d6a57adc480c5ce71565a4f3
|
|
| MD5 |
ce1333a5dca540a6e5d5289b86b4412f
|
|
| BLAKE2b-256 |
b56dbbc5cb591f7e1dc3c766752f12755e096294eba1b29453f44d7adb2b2964
|
Provenance
The following attestation bundles were made for apmodel-0.5.4.tar.gz:
Publisher:
publish.yml on fedi-libs/apmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apmodel-0.5.4.tar.gz -
Subject digest:
526a830fe10e3b2b6ba18ddb390e04ecd5d77490d6a57adc480c5ce71565a4f3 - Sigstore transparency entry: 867456658
- Sigstore integration time:
-
Permalink:
fedi-libs/apmodel@942249758f18dcc0594813a100327d992b8cf2dc -
Branch / Tag:
refs/tags/0.5.4 - Owner: https://github.com/fedi-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@942249758f18dcc0594813a100327d992b8cf2dc -
Trigger Event:
release
-
Statement type:
File details
Details for the file apmodel-0.5.4-py3-none-any.whl.
File metadata
- Download URL: apmodel-0.5.4-py3-none-any.whl
- Upload date:
- Size: 69.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f1dc4c1891b9456d77cde3c1c0f929233f66419e4c7365634d54bab422a7734
|
|
| MD5 |
a7477662b9c529d6b17ac22578031eeb
|
|
| BLAKE2b-256 |
a974560b6f4bf03d1de0010ea6e3049240826d3b8e2fdc46ddd730cbc659138d
|
Provenance
The following attestation bundles were made for apmodel-0.5.4-py3-none-any.whl:
Publisher:
publish.yml on fedi-libs/apmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apmodel-0.5.4-py3-none-any.whl -
Subject digest:
0f1dc4c1891b9456d77cde3c1c0f929233f66419e4c7365634d54bab422a7734 - Sigstore transparency entry: 867456661
- Sigstore integration time:
-
Permalink:
fedi-libs/apmodel@942249758f18dcc0594813a100327d992b8cf2dc -
Branch / Tag:
refs/tags/0.5.4 - Owner: https://github.com/fedi-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@942249758f18dcc0594813a100327d992b8cf2dc -
Trigger Event:
release
-
Statement type: