Skip to main content

Python application component initialization system

Project description

systemPY

Logo

Python application component initialization system

python version downloads format Documentation Status GitHub issues Ruff Checked with mypy

Full documantation is available at Read the Docs

The problem

The regular application contain many atomic components. Asyncio makes theirs initializing a little bit complicated. It's OK, when you have single entrypoint and initialize your application components via your framework. While you add new components to your application iteratively, you don't see any problem

When you create any new entrypoint, you have to think a lot, how to initialize application components again, which callbacks should be called and in which order. But it's a half of the problem! You have to implement also graceful shutdown

The most painful part is one-time scripts. It's kind of The Banana Gorilla Problem: you wanted a banana but you have to initialize a gorilla holding the banana and the entire jungle, and then graceful shutdown it

Solution

This library allows you to implement application startup and shutdown in declarative way. You have to implement a class for each your component, write the startup and shutdown code. Then combine required components as mixins into the current application Unit class. Then create an instance and pass dependencies as keyword arguments. In case it's daemon run instance.run_sync() methed

Basic principles

There are 6 most significant stages of the application lifecycle:

  • on_init executes exactly once on application startup

  • pre_startup is called before event loop startup

  • on_startup is called exactly when event loop started

  • on_shutdown is called when application is going shutdown or reload but event loop still working

  • post_shutdown is called after event loop stopped or drained. When application is going to reload, then it should be called pre_startup

  • on_exit executes exactly once when application is stopping

You may to create Unit classes for each your application component where you may put your code. Then you may combine these Unit class mixins into the current worker class, which aggregate your defined callbacks and run in the right order. Depending on application type, these callbacks may be called by primary application or by you are

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

systempy-0.1.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distributions

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

systempy-0.1.2-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

systempy-0.1.2-cp313-cp313-macosx_14_0_arm64.whl (314.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

File details

Details for the file systempy-0.1.2.tar.gz.

File metadata

  • Download URL: systempy-0.1.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.3

File hashes

Hashes for systempy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6c31094e44d4056f475d16c0363f4f1767462a0f082fc5249f3680aae02044a8
MD5 402f458c45a527fdfde5f48ed0961ff7
BLAKE2b-256 217f5d68532cca92cba4abbebbc4a4a7f0096a78e8aae408f23f3e785276226d

See more details on using hashes here.

File details

Details for the file systempy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: systempy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.3

File hashes

Hashes for systempy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d9de39377b3e2fc7800137396fc068cf7febcc5a1f0ff967952d9334c44e3cbf
MD5 d4276ec48aff149532aa199f4bffc8a4
BLAKE2b-256 6c6c0784cef1720c7b4fc0b7db6e2216685eb9e6b893af99f030a8ac59387f2a

See more details on using hashes here.

File details

Details for the file systempy-0.1.2-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for systempy-0.1.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dce39ba8f2dc955d7321058d48f4d635ba94de2a0cf5da2f161ee1ee8d8f1694
MD5 820aedfecd447fae6b0093741e322b8a
BLAKE2b-256 40ef4ec3c76a17d5ab78c447f30b25eb08981d821baaa651c14eff8d2826123d

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