Skip to main content

jaraf


Just another rakish application framework.

Overview


JARAF is an application framework, which just just a fancy name for a collection of python code that can help jumpstart the development of command-line tools and applications, providing a developer is willing to follow a few rules and conventions to use the framework.

The framework itself is fairly straighforward to use. An application will inherit from a base application class named jaraf.App and implement one required method (jaraf.App.main()). From there, the application can optionally implement a number of other prescribed methods to set up and customize itself. For example, an application that needs custom command-line arguments will implement the jaraf.App.add_arguments() and jaraf.App.process_arguments() methods.

A lot of simple applications will probably only ever need the jaraf.App class, but for more complex applications, additional features are provided through mixin classes.

Application Base Class


The application base class, jaraf.App, is a virtual base class that must be inherited by an application in order to use the framework. It provides some basic features useful to most command-line applications. This includes exception handling to prevent an application from abruptly exiting, a best-effort exit code, logging methods, and built-in command-line arguments to set various parameters.

It has one virtual method named :meth:jaraf.App.main() that must be implemented. A minimalist application need only implement this one method to use the framework. However, there are other virtual methods that can be implemented and public methods that can be overloaded that enable developers to further customize an application.

Here's the obligatory starting example:

from jaraf import App

class HelloWorldApp(App):
    def main(self):
        self.log.info("Hello, World!")
        raise RuntimeError("Aaand goodbye...")

if __name__ == "__main__":
    app = HelloWorldApp()
    app.run()

When saved to file named hello_world.py and run, it will print something like the following output to the terminal::

2018-04-10 22:00:10,379 INFO ---------------------------------------------------------------
2018-04-10 22:00:10,379 INFO STARTING hello_world.py
2018-04-10 22:00:10,379 INFO Hello, World!
2018-04-10 22:00:10,379 ERROR Unhandled exception: Aaand goodbye...
2018-04-10 22:00:10,379 ERROR > Traceback (most recent call last):
2018-04-10 22:00:10,379 ERROR >   File "/lib/python/jaraf/app/__init__.py", line 218, in run
2018-04-10 22:00:10,379 ERROR >     self.main()
2018-04-10 22:00:10,379 ERROR >   File "./hello_world.py", line 5, in main
2018-04-10 22:00:10,379 ERROR >     raise RuntimeError("Aaand goodbye...")
2018-04-10 22:00:10,379 ERROR > RuntimeError: Aaand goodbye...
2018-04-10 22:00:10,379 INFO FINISHED hello_world.py
2018-04-10 22:00:10,379 INFO - Exit status: 1

It's an underwhelming example to be sure, but for a few lines of code, we get a timestamped output format (even the stack trace is properly formatted) and logged callouts for the start, finish and exit status of our applications. Plus if you bring up the help text with hello_world.py -h, you'll see a handful of options that were automatically added to our application.

Mixins


Mixins provide additional functionality to an application through multiple inheritance with each mixin class usually providing just a narrow feature set. The philosophy here is that applications should not be bloated by code that is never going to be run. Instead, an application should be able to selectively load just the functionality it needs.

For example, to add support for logging to a file, an application class could be defined like so:

from jaraf import App
from jaraf.mixin.cron import CronMixin
from jaraf.mixin.logfile import LogfileMixin

class HelloWorldApp(LogfileMixin, App):
    # Class definition follows...

Download files

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

Source Distribution

jaraf-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

jaraf-0.1.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jaraf-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for jaraf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 70ddc6feab5132c14daae7918a93ef9adce77366451b49f580fadca16f60e22d
MD5 782f39520dc901ad770637d1a75f87b2
BLAKE2b-256 22df97e291ea54034fb6fcc60a1d5ac751fc8990759577dc164c86e77422d099

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jaraf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for jaraf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65420ec3800f9f57ba67ae919b03e0b56f0d3c2c4603e27952bcc77ed5606074
MD5 93f1d14c58ee219efb564bfc8f06f3f3
BLAKE2b-256 f9fc7806bb9d3e190694ba55b8fc6cf7173bf7139b014989add4637a0d111c30

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

This release

0.1.1 This release

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