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.1.tar.gz (20.9 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.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

systempy-0.1.1-cp313-cp313-manylinux_2_39_x86_64.whl (323.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

File details

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

File metadata

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

File hashes

Hashes for systempy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 987791ae494b2a35b841e66bb0215260407d41cd90bb37a9a680bdeae1a7d11f
MD5 9e93ffcbbe22f6c547740bfb5eba25f3
BLAKE2b-256 1faaf5a99f6ba46f02b89265c9ec97a06b16258ac8b1882ea2d0951ac50a4d31

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for systempy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16d5329ead4af1c8da6bbfbb843903b6f9f431452d20dff93dc608b6bbeca961
MD5 b4a7ee07b45732449c3e832559448a5f
BLAKE2b-256 673920a95e2e4943e308fda8c56d847bf62e8c1ab63499b0a302630c4e30e361

See more details on using hashes here.

File details

Details for the file systempy-0.1.1-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for systempy-0.1.1-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ab3a0171a29b0d5ef60c4ca1e2f9f9c4912c3ba2469bf3f7c159c1c66d68d7c2
MD5 c4b718f45c6c50c6853ca48e7acb9fa7
BLAKE2b-256 97271c84b6cd2075b0e6b7f084122fbe3794cb40011af6bce6aa128848e5a95f

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