clientwrapper


Nameclientwrapper JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryPython Util Package for inheriting Argparse behavior
upload_time2024-09-18 16:32:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # clientwrapper (licensed under Apache 2.0)
Util class enabled CLI/dictionary syntax: allows separation of concerns between CLI and Python code.

## installation
```bash
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.
```bash
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.
```bash
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.
```python
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. 
```bash
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.
```python
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.
```python
from src.etc.package import Impl

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

if __name__ == '__main__':
    main()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "clientwrapper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Joseph Gonzalez Diaz <jgonzalezdiaz@ebay.com>",
    "download_url": "https://files.pythonhosted.org/packages/a9/5a/570b61158b6080628ed8e9671526c506e9bb2325ddd34838f626b9b99726/clientwrapper-1.0.1.tar.gz",
    "platform": null,
    "description": "# clientwrapper (licensed under Apache 2.0)\nUtil class enabled CLI/dictionary syntax: allows separation of concerns between CLI and Python code.\n\n## installation\n```bash\npip install clientwrapper\n```\n\n## usage \n### overview\nClientWrapper is a class that allows you to define functions that can be run in both CLI and Python syntax.\n\n### run in CLI\nRunning as a CLI requires all functions with arguments to run in one combined function. The below command will not run as a CLI.\n```bash\npython3 -m yourmodule authenticate --arg1 value1 --arg2 value2\n# self.attributes like authentication tokens are erased every time the CLI is run; combine your functions to avoid NullPointerExceptions\npython3 -m yourmodule query --argument value # will not work: relying on any attributes in self\n```\nBelow is an example of how to run as a CLI.\n```bash\npython3 -m yourmodule authenticate_and_query --arg1 value1 --arg2 value2 --argument value\n```\n\n### usage example\nDefine your class here and inherit from ClientWrapper; combined function is required to run as a CLI.\n```python\nclass Impl(ClientWrapper):\n    def __init__(self):\n        super().__init__(\"Some API Requests\")\n\n    def login(self, username, password):\n        print(\"login called with username: \" + username + \" and password: \" + password)\n\n    def getRequest(self, argument):\n        print(\"getRequest called with argument: \" + argument)\n\n    def postRequest(self, **kwargs):\n        print(\"postRequest called with arguments: \" + str(kwargs))  \n\n    def login_and_get_request_and_post_request(self, username, password, argument, **kwargs):\n        self.login(username, password)\n        self.getRequest(argument)\n        self.postRequest(**kwargs)\n```\n\n### test in CLI\nUse CLI syntax to run your functions. \n```bash\npython3 -m yourmodule login_and_get_request_and_post_request --username myusername --password mypassword --argument [1, 2] --arg1 value1 --arg2 value2\n```\n\n### test in Python \nUse argparse-like syntax in Python for testing purposes.\nNote that Clientwrapper takes strings, ints, lists, tuples, and dictionaries as arguments but containers must be passed as strings.\n```python\nimpl = Impl()\nimpl.run([\n    'login_and_get_request_and_post_request --username myusername --password mypassword --argument \"[1, 2]\" --arg1 value1 --arg2 value2'.split()\n])\n>>> login called with username: myusername and password: mypassword\n>>> getRequest called with argument: [1, 2]\n>>> postRequest called with arguments: {'arg1': 'value1', 'arg2': 'value2'}\n```\n\n### test in CMD prompt as CLI\nYour module will require a __main__.py in order to run as a CLI; here is a simple example.\n```python\nfrom src.etc.package import Impl\n\ndef main():\n    impl = Impl()\n    impl.run()\n\nif __name__ == '__main__':\n    main()\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python Util Package for inheriting Argparse behavior",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/ebay/clientwrapper",
        "Issues": "https://github.com/ebay/clientwrapper/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6fd3762e232ed6c33c98db05c03aa49f9f95fb08582dae076dc82ff0b2fa8db6",
                "md5": "aa7f3d25a5febc9439c6c391cd25a10d",
                "sha256": "0857a1ded3a653b23b1f9244a73a5be23759ef7373cac9cc92bc5529272e4622"
            },
            "downloads": -1,
            "filename": "clientwrapper-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aa7f3d25a5febc9439c6c391cd25a10d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11965,
            "upload_time": "2024-09-18T16:32:46",
            "upload_time_iso_8601": "2024-09-18T16:32:46.950916Z",
            "url": "https://files.pythonhosted.org/packages/6f/d3/762e232ed6c33c98db05c03aa49f9f95fb08582dae076dc82ff0b2fa8db6/clientwrapper-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a95a570b61158b6080628ed8e9671526c506e9bb2325ddd34838f626b9b99726",
                "md5": "3c163db4ca9b6a26627c04df3e973428",
                "sha256": "3bf3150b899e3f2dcc9c72cee4d9ca71b169058f36dc5d934013185aad7662be"
            },
            "downloads": -1,
            "filename": "clientwrapper-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3c163db4ca9b6a26627c04df3e973428",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9839,
            "upload_time": "2024-09-18T16:32:50",
            "upload_time_iso_8601": "2024-09-18T16:32:50.423946Z",
            "url": "https://files.pythonhosted.org/packages/a9/5a/570b61158b6080628ed8e9671526c506e9bb2325ddd34838f626b9b99726/clientwrapper-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-18 16:32:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ebay",
    "github_project": "clientwrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "~=",
                    "2.31.0"
                ]
            ]
        }
    ],
    "lcname": "clientwrapper"
}
        
Elapsed time: 0.40073s