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

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.0.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

systemPY-0.0.4-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file systemPY-0.0.4.tar.gz.

File metadata

  • Download URL: systemPY-0.0.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for systemPY-0.0.4.tar.gz
Algorithm Hash digest
SHA256 dcee10a433212abbed8c95d255c9a77bb75553d2ac96a884b2f86257e4ad84da
MD5 f87053ef92037627cc42edf3b9e12191
BLAKE2b-256 c8758036a54e408421faf8d550f56f76b66babc8ff2f0af23007c4c44fe3eccd

See more details on using hashes here.

File details

Details for the file systemPY-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: systemPY-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for systemPY-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b4ee06daf3fe2f45c2e5032cef0c580650b223fb1e718dac70fce90e08875694
MD5 3c1b5017715f996afdc08d6a764aa51d
BLAKE2b-256 7596cc07d85a27d4baaf5b3dae35ae932e91d683978a948d7529302d81bcb9cc

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