Skip to main content

PerFact API Base

The main FastAPI package for the PerFact API. Provides authentication, authorisation, database session handling, and plugin discovery. All domain-specific API modules are in separate packages and loaded automatically at startup via entry points.

Applications

perfact.api.main.app — user-facing API

Hosts all plugins registered under the perfact.api entry point group. All routes are served under the /api path prefix. Users authenticate via a login cookie or an Authorization: Apikey … header. Access to individual endpoints can be restricted by role:

from perfact.api.main.auth import require_roles

@router.get("/my-endpoint")
@require_roles("MyRole")
def my_endpoint(session: DBSession) -> ...:
    ...

perfact.api.main.assignworker — task runner API

Hosts all plugins registered under the perfact.assignapi entry point group. All routes are served under the /assignworker path prefix. Intended for internal use by assignd. Authentication is HTTP Basic Auth with a pre-shared password hash configured in the YAML config file.

Plugin discovery

At startup, both apps iterate over their respective entry point group and call mount(app) on each discovered plugin:

INFO - start plugin discovery
INFO - try to include plugin: perfact.api.pd.routes:mount
INFO - finished discovery and include: 1 plugins

A plugin registers itself by declaring an entry point in its pyproject.toml:

[project.entry-points.'perfact.api']
myplugin = 'perfact.api.myplugin.routes:mount'

getting started as developer

After you checked out this repository, do the following steps to be able to debug your application:

  1. create and activate venv
    python -m venv .venv
    
    source .venv/bin/activate # linux
    .venv/Scripts/Activate.ps1 # PowerShell
    
  2. Install the API plugins you want to include without doing changes by installing them from pypi:
    pip install perfact-api-base
    
  3. Install the API plugins you want to include and change in your instance by checking them out somewhere and installing/linking them into your application via pip install -e:
    pip install -e ../perfact-api-base/ # required
    pip install -e ../perfact-api-app/app/ # required
    pip install -e ../perfact-api-pd-model/ # example
    

Hint: Every code change is available in the application after the next restart/reload. Changes to the entrypoints are available after the next install command execution (as this is recreating the ENTRYPOINTS-file belonging to the package in the site-packages folder).

You can install as much as plugins you like, even custom ones.

pip will automaticly check if more dependencies needed by the plugin while installing, e.g.

Requirement already satisfied: fastapi

Now you can run the application:

uvicorn perfact.api.main.app:app # run API for frontend
uvicorn perfact.api.main.assignworker:app # run API for assignd worker APIs
uvicorn perfact.api.main.app:app  --reload --reload-include ../ # run API for frontend with auto-reload for all editable dependencies

There is a launch.json-file provided to debug the application in VS Code. To use that, you have to create a configuration file (see below).

Configuration

The application can be configured by providing a configuration yaml-File containing informations about the database connection and basic auth credentials (for assignworker). The configuration file is given to the application by providing the location (absolute or relative to working dir) in the environment variable PERFACT_API_CONFIG_PATH.

Example:

connstr: postgresql+psycopg://zope@/perfactema # default, can be left out
basicauth: "$argon2id$v=19$m=65536,t=3,p=4$6itEouPTNwWEXDKScKmMrw$NwhN1vAUN8EZjC62HrtXjx7n+K1Mujjd/QqioaHvyOg" # password=test

Dependencies

  • perfact-api-app
  • fastapi
  • sqlalchemy
  • psycopg[c]
  • argon2-cffi
  • pydantic-settings

Maintainers

Download files

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

Source Distribution

perfact_api_main-1.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

perfact_api_main-1.1-py2.py3-none-any.whl (15.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file perfact_api_main-1.1.tar.gz.

File metadata

  • Download URL: perfact_api_main-1.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for perfact_api_main-1.1.tar.gz
Algorithm Hash digest
SHA256 38f59611dae3f59521da119b26d500bf63476c5bb23aaa5722b3931cb29724fd
MD5 7c0a0403bd126d6f450ee4ce7306b625
BLAKE2b-256 23351f8dd75226b52622bdb2795084d5d0dd18e25c4cf7a0e05bff4ba6800dad

See more details on using hashes here.

File details

Details for the file perfact_api_main-1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for perfact_api_main-1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d4bdc9fbee21dd5951e51292c89d1325257881d5b5bdde567330ac60d9482647
MD5 00c43e6c75d933a580884bd7a2e55f1f
BLAKE2b-256 9097c5a9865135cf90e9d53e5080767c1a0cc633d24475a0d23b48c9c24927b6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1 This release

2 files

1.0

2 files

0.9

2 files

0.8

2 files

0.7

2 files

0.6

2 files

0.5.0

2 files

0.3

2 files

0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page