Skip to main content

Simple Scripting Wrapper

Project description

efficient-app - Simple Scripting Wrapper

Script configuration and logging setup

Usage

Here's an example of a simple entry to a script, it also uses the package 'efficient-args', but that isn't required to use this package, the args just need to be returned as a dictionary:

    from kisspy.decorators.pidFile import pidFile
    from efficient_args import FORMATTER, addBaseArgs, parseArgs
    from efficient_app import appWrapper
    import argparse
    import logging
    import time


    def getArgs() -> dict:
        parser = argparse.ArgumentParser(description="Example App", formatter_class=FORMATTER)
        addBaseArgs(parser, addEnvironment=True)
        return parseArgs(parser)


    @pidFile()
    @appWrapper("myapp", cmdArgs=getArgs())
    def yourProgramStartPoint(*args, **kwargs):
        logger = logging.getLogger(__name__)
        logger.debug("Do A Bunch Of Stuff Here!")
        # raise Exception("Doh!!")
        logger.info("KWARGS: {}".format(kwargs))
        time.sleep(1)
        logger.info("Done!!")


    if __name__ == "__main__":
        yourProgramStartPoint()

The kwargs dict passed into the start point method looks like this, obviously the actual data would look different, but from there you can call your methods...

{
    "appCfgDir": "wkdir/test/cfg/",
    "appCfg": {
        "dbConn": "host=<fqhostname> dbname=<dbname> user=<usr> password=<pswd>",
        "api": {
            "baseUrl": "<http://baseurl>",
            "apiKey": "<apikey>"
        }
    },
    "appArgs": {
    },
    "cmdArgs": {
        "environment": "test"
    }
}

By default, the configuration and log files are created in this structure at the root of the project directory:

wkdir/
├── prod
│   ├── cfg
│   │   ├── appCfg.json
│   │   └── logCfg.json
│   └── logs
│       ├── appLog.txt
│       └── unhandled_exc_20260320T002548.txt
└── test
    ├── cfg
    │   ├── appCfg.json
    │   └── logCfg.json
    └── logs
        ├── appLog.txt
        ├── appLog.txt.2026-03-12
        ├── appLog.txt.2026-03-17
        ├── unhandled_exc_20260312T202100.txt
        └── unhandled_exc_20260312T202244.txt

Note that when the script encounters an unhandled exception, it will save the stack trace to a date and time stamped file for reference. This occurs when the app first runs, as it creates a default app config file and assumes the default isn't going to cut it. Edit to your hearts content and re-run.

The package also contains two methods to assist with temp directories:

    from efficient_app import createDTUniqueTempDir, cleanUpTempDirs
    from datetime import timedelta

    # create the temp directory
    dirPath = createDTUniqueTempDir(baseDir="wkdir/dev/files/")
    # ...
    # do some stuff with the files added to the directory
    # ...
    # at some point in the future, if you want to clean it up...
    cleanUpTempDirs(baseDir="wkdir/dev/files/", olderThan=timedelta(days=90))

Installation

Using In Projects

Installation:

    pip install efficient-app

Cloning For Development

Set up a virtual environment. Once an environment is set up, run the command below to:

  • validate the environment variable
  • activate the environment (if not already activated)
  • install all of the necessary packages into the local environment
    pip install -U -r requirements/dev.txt

The dev.txt file includes:

  • BLACK, a code formatter, see notes at the bottom of this file for details

Dependancies

This project uses the following projects:

  • kisspy-python
  • distlib

Tests

To run tests:

    python -m unittest discover -s tests/

Code Formatting

Code formatting is done using BLACK. BLACK allows almost no customization to how code is formatted with the exception of line length, which has been set to 119 characters.

Use the following to bulk format files:

    black . -l 144

Creating A New Release

Please do the following when making a new release, most are documented above:

  1. Run tests
  2. Code format
  3. Be sure to update the change log and _metadata.json with version and notes
  4. git add, commit, and push changes
  5. run the following code to generate a wheel:
    python -m build

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

efficient_app-0.5.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

efficient_app-0.5.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file efficient_app-0.5.0.tar.gz.

File metadata

  • Download URL: efficient_app-0.5.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for efficient_app-0.5.0.tar.gz
Algorithm Hash digest
SHA256 118756da0b4d66ea28ff6dc69455506c5273e612c4103c688155f927ffd0646f
MD5 6d5a007d5575bcdc688510957aa3ad9e
BLAKE2b-256 ae47d6713b2af82bb3fe5eff752f47803da5c42cdb9ce71c0b76ebac617ba0f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for efficient_app-0.5.0.tar.gz:

Publisher: publish.yml on joemarchionna/efficient_app

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file efficient_app-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: efficient_app-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for efficient_app-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d8178b44ff3505473415964d6c74dda9d26fa25d9b2672f7e69e2b2e25343d7
MD5 f7275309ed35b60273283c96be551e36
BLAKE2b-256 71c46718e4e603f9bb0a4efb33946c3bc8dbf8853f0666de5223fed33bd83b53

See more details on using hashes here.

Provenance

The following attestation bundles were made for efficient_app-0.5.0-py3-none-any.whl:

Publisher: publish.yml on joemarchionna/efficient_app

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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