Skip to main content

Python Util Package for Applying Dictionary syntax

Project description

clientwrapper (licensed under Apache 2.0)

Util class enabled CLI/dictionary syntax: allows separation of concerns between CLI and Python code.

installation

pip install clientwrapper

usage

overview

ClientWrapper is a class that allows you to define functions that can be run in both CLI and Python syntax.

run in CLI

Running as a CLI requires all functions with arguments to run in one combined function. The below command will not run as a CLI.

python3 -m yourmodule authenticate --arg1 value1 --arg2 value2
# self.attributes like authentication tokens are erased every time the CLI is run; combine your functions to avoid NullPointerExceptions
python3 -m yourmodule query --argument value # will not work: relying on any attributes in self

Below is an example of how to run as a CLI.

python3 -m yourmodule authenticate_and_query --arg1 value1 --arg2 value2 --argument value

usage example

Define your class here and inherit from ClientWrapper; combined function is required to run as a CLI.

class Impl(ClientWrapper):
    def __init__(self):
        super().__init__("Some API Requests")

    def login(self, username, password):
        print("login called with username: " + username + " and password: " + password)

    def getRequest(self, argument):
        print("getRequest called with argument: " + argument)

    def postRequest(self, **kwargs):
        print("postRequest called with arguments: " + str(kwargs))  

    def login_and_get_request_and_post_request(self, username, password, argument, **kwargs):
        self.login(username, password)
        self.getRequest(argument)
        self.postRequest(**kwargs)

test in CLI

Use CLI syntax to run your functions.

python3 -m yourmodule login_and_get_request_and_post_request --username myusername --password mypassword --argument [1, 2] --arg1 value1 --arg2 value2

test in Python

Use argparse-like syntax in Python for testing purposes. Note that Clientwrapper takes strings, ints, lists, tuples, and dictionaries as arguments but containers must be passed as strings.

impl = Impl()
impl.run([
    'login_and_get_request_and_post_request --username myusername --password mypassword --argument "[1, 2]" --arg1 value1 --arg2 value2'.split()
])
>>> login called with username: myusername and password: mypassword
>>> getRequest called with argument: [1, 2]
>>> postRequest called with arguments: {'arg1': 'value1', 'arg2': 'value2'}

test in CMD prompt as CLI

Your module will require a main.py in order to run as a CLI; here is a simple example.

from src.etc.package import Impl

def main():
    impl = Impl()
    impl.run()

if __name__ == '__main__':
    main()

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

clientwrapper-1.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

clientwrapper-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file clientwrapper-1.0.0.tar.gz.

File metadata

  • Download URL: clientwrapper-1.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for clientwrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 807954b664d3bafe4637c3c150bd7ecef2aae57132b41e7869efb8f92b25b593
MD5 ba13b13e2f8e59b95eb5ddf863abecfd
BLAKE2b-256 9b8013af9ffed7e9c35b6bdb9ce2589a5322363815241f6000152b74a497a76a

See more details on using hashes here.

File details

Details for the file clientwrapper-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: clientwrapper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for clientwrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfae87fea78c375ef7f899a4f9923012e1a619e792092ddd5e62aa3281d7a782
MD5 5fd197c8d11eb58e7cad03ae0e4beb38
BLAKE2b-256 143293fdddb12e8eb8881105e731ba5901db63f4ad7074d038115124590e454e

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