Skip to main content

Fractal Application

Fractal Application is the top of the Fractal stack: the application context that installs an application's repositories and services, wires its command bus and event publisher, and health-checks them on startup.

PyPI Version Build Status

Installation

pip install fractal-application
pip install fractal-application[fastapi]        # FastAPI ingress
pip install fractal-application[gcp]            # Firestore event store, Pub/Sub projector
pip install fractal-application[processes]      # event → Process mappers

Background

This is the layer that knows about all the others. fractal-core, fractal-commands, fractal-events and fractal-processes are all deliberately ignorant of it, which is what lets any of them be used on their own. Everything that has to know how the pieces fit together lives here.

The application context

from fractal_application import ApplicationContext
from fractal_core import Settings


class AppSettings(Settings):
    def load(self):
        self.EVENT_STORE_BACKEND = os.getenv("EVENT_STORE_BACKEND", "memory")


class Context(ApplicationContext):
    settings = AppSettings()


@ApplicationContext.register_repository("user_repository")
def select_user_repository(settings):
    return MongoUserRepository(settings.MONGO_URL)


@ApplicationContext.register_command_handler
class AddUserCommandHandler(CommandHandler):
    ...


context = Context()          # loads services, repositories, bus, publisher
context.user_repository      # installed and health-checked
context.command_bus          # every registered handler already on it

Construction is the wiring check. load() installs internal services, repositories, egress services, the event publisher, the command bus and ingress services, then asserts every repository and service reports itself healthy. A context that constructed is a context whose adapters answered.

Registration happens through decorators at import time, which means it is a side effect of the import graph — if a module holding handlers is never imported, its handlers are never registered. fractal-commands raises on a command with no handler precisely because that failure is otherwise silent.

Fractal

from fractal_application import Fractal


class MyService(Fractal):
    settings = AppSettings()
    context = Context()

Instantiating it asserts the service was wired: a Fractal without settings or without a context refuses to construct rather than failing later on the first attribute nobody set.

contrib

FastAPI

from fractal_application.contrib.fastapi.install import install_fastapi

app = install_fastapi(context, title="My Service")

Also provides the default REST routers, token/role dependencies, an error response model and a JSON encoder that understands pydantic models.

Google Cloud

FirestoreEventStoreRepository backs the event store with Firestore (selected by EVENT_STORE_BACKEND=firestore), and PubSubEventBusProjector publishes events onto a Pub/Sub topic when GCP_PROJECT_ID is set.

Processes

Event → Process mappers need fractal-processes. The context passes itself to the projector as context_func, so the process engine gets an application context without fractal-events ever importing this package.

Development

make dev-install
make test
make lint
make format

Metadata

Release files for fractal-application 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fractal-application 2.1.0
File Size Uploaded Provenance Actions
fractal_application-2.1.0.tar.gz 14.7 kB Without provenance Details for fractal_application-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fractal-application 2.1.0
File Interpreter ABI Platform Actions
fractal_application-2.1.0-py3-none-any.whl Python 3 none any Details for fractal_application-2.1.0-py3-none-any.whl

Total release size: 32.3 kB

Release files / fractal_application-2.1.0.tar.gz

Download URL fractal_application-2.1.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
49e00ed39c2bdea504af274381db5f605f82d607603142baf05530dd135efcdc
BLAKE2b-256 checksum
How to use checksums
1a80ec6a52411040fc6d38083ef0360f5385768d08a5e4cc167bd3bd3a134a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release files / fractal_application-2.1.0-py3-none-any.whl

Download URL fractal_application-2.1.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a67bf392327279837140276499b2ce083c00aff310d46f753714bbee1b38e93
BLAKE2b-256 checksum
How to use checksums
1da1f596a03d425a340779df2f5f77e7e1f1f0df3f64656533b66785f191f846
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Security for fractal-application 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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