Skip to main content

Phederation implementation of ActivityPub. Can be used to setup a server in the fediverse, and can also be used as a library to build clients connecting to these (and other ActivityPub) servers.

Project description

A python/fastAPI implementation of the ActivityPub protocol.

Requirements

  • Linux environment (tested on Mint/Ubuntu)

  • Python (3.12+)

Installation

  1. As a pip package:

If you want to build ActivityPub clients, you can use the software as a library.

pip install phederation
  1. For development of the library, clone the repository from codeberg:

git clone https://codeberg.org/feldie/phederation.git phederation
  1. Navigate to the root folder of the “phederation” repository, then set up a python environment with uv, e.g.:

cd phederation
uv sync
  1. You can start a debug/development version using:

source .venv/bin/activate
gunicorn -c=settings/gunicorn.conf.dev.py

This will start a local server (localhost), you can try to access the fastapi doc at “<localhost:port>/docs”.

Testing and profiling

There are unit tests in the tests/ folder. They can be run using pytest:

pytest tests/unit_tests/

For coverage:

coverage run -m pytest tests/
coverage html

Profiling can be done with the pytest plugin pytest-profiling. For pretty svg plots of the runtimes, we use the additional graphviz tool.

pip install pytest-profiling
sudo apt install graphviz
pytest tests/unit_tests/ --profile-svg

Production environment

For a production environment, you should set up proper web hosting. Minimal safeguards should be in place, at least proxy+load balancing+ddos safe; nginx+fail2ban are a good combination:

You should also use a proper WSGI webserver (e.g. gunicorn), see below. Phederation is set up to accommodate all of this, and is tested to work in a production environment. Example settings files for production can be found in the “settings” folder. After setting up fail2ban and nginx, you can start a production mode version like this (including creating a logs folder if it does not exist yet):

source .venv/bin/activate
mkdir logs
gunicorn -c=settings/gunicorn.conf.prod.py

The command above starts gunicorn workers and serves content on “127.0.0.1:8082” (localhost, then use proxy to serve on the web). It uses the settings file “settings/instance_config-prod.yaml” for production mode.

Of course, it is useful to convert this into a proper service that runs continuously. This can be done by containerization of the phederation server itself, building a docker image and then hosting it. It is important to first set the proper variables in the file settings/.env (an example file with dummy values is located in settings/.env.noignore), then build the docker image, and then start all docker images. Note that the docker compose file settings/compose.yaml will start a keycloak server, its postgres database, a mongo database for the phederation image, and the phederation image itself. If you have another keycloak server running already, you should disable the former in the settings/compose.yaml file and instead link to yours in the settings/.env file.

docker build -t phederation-0.1
docker compose up -d

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phederation-0.4.8.tar.gz (137.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phederation-0.4.8-py3-none-any.whl (193.3 kB view details)

Uploaded Python 3

File details

Details for the file phederation-0.4.8.tar.gz.

File metadata

  • Download URL: phederation-0.4.8.tar.gz
  • Upload date:
  • Size: 137.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for phederation-0.4.8.tar.gz
Algorithm Hash digest
SHA256 4261d45e21674261f484db797caeb0c6957379b7d7bf295fc9e125469e688ad0
MD5 3c8597f625ce065297044ac06f8d9436
BLAKE2b-256 13d7014dc491b179ee805e3aca6c2c8541bc343563b3ce9462efe46ca39e754d

See more details on using hashes here.

File details

Details for the file phederation-0.4.8-py3-none-any.whl.

File metadata

  • Download URL: phederation-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 193.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for phederation-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2b837304a78d0af562e282f0f64a3f31183f895102dbcc51abbd93ae843e8c1d
MD5 d4ea4c5aa03e74bfcfefab331f74537d
BLAKE2b-256 06d876599946207f75a8a5316dc1bf5e6f21c4dd80be03f57477c5ac01be753c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page