Skip to main content

some description

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.3.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.3.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: efficient_app-0.3.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.7

File hashes

Hashes for efficient_app-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6bc24486a9d718ecdfa15c543dcb2d0218eff507a4c25f649639787674fd5fec
MD5 3683a289629b081e5289d13b1af1ee8b
BLAKE2b-256 6cdd30458bb71092a5efc5f34fdb3f3ca893988960c263bbc1a9fd0b016fca57

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for efficient_app-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e74b612ddaaf5f99add58cd4b35c7b07a1b4f42309932434c006910904887e9b
MD5 2aebeb9475bb801adc559c2dae409726
BLAKE2b-256 84eef4aaee3542676fd9a303149b8f57e17a5ca0067b43c7972036aa691589e6

See more details on using hashes here.

Provenance

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