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.4.0.tar.gz (11.7 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.4.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: efficient_app-0.4.0.tar.gz
  • Upload date:
  • Size: 11.7 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.4.0.tar.gz
Algorithm Hash digest
SHA256 61a410357a637f712186850d0a2a714e1b0a7570625587a09543116779911041
MD5 15386c2173d425209a5463668455c978
BLAKE2b-256 edb027457984e227e7e79992efb9e00358fe974b2191c8e216c8b7393d9e037b

See more details on using hashes here.

Provenance

The following attestation bundles were made for efficient_app-0.4.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.4.0-py3-none-any.whl.

File metadata

  • Download URL: efficient_app-0.4.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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1cbcbd25e5775f2d9f91dbcb8fa68e1f59dd7175becc60ffed23be48d84af8c
MD5 d92f5660b1eedd1ad0eb998a605721a3
BLAKE2b-256 7cebe21a8216f819bc4a65875a5ba44e4096229e7ab356911b89d83a7428d240

See more details on using hashes here.

Provenance

The following attestation bundles were made for efficient_app-0.4.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