# Rest tool
> A curated list of awesome things related to microservices and computer vision.
This module contains interesting features for endpoint creation. It also includes some decorators.
## Details
- Decorest - class decorator that allows implementing a general try_log function in the entire function, but it is necessary to use the ResData data model
## Installation
Use the package manager pip to install restutil.
```bash
pip install restutil
```
## Usage
- Decorest
```python
from restutil.decorators import Decorest
# create decorest object
deco = Decorest()
# wrap foo function
@deco.try_log
def foo():
return None
```
- ResData, ResOperationType
```python
from restutil.result import ResData
from restutil.operations import ResOperationType as resType
# create ResDaata object
result: ResData = ResData()
# add data in its content
result.content = "data"
# add flagged results
result.add_result(message=str(f'Error occurred'), res_type=resType.ERROR)
# check flags
bool(result.has_errors)
```
- Logger
```python
from restutil.logger import Log
from restutil.logger import LoggerMinimumLevel as level
import os
# Setting to file
local_path = '%s/%s' % (os.path.dirname(__file__), 'Log')
lg = Log().setting_to_file(logger_path=local_path, logger_file_name='Test', minimum_level=level.DEBUG)
lg.info('Test Dummy')
# Setting to logstash
import sys
hostLogstash = '127.0.0.1'
portLogstash = 5959
lg = Log().settingToLogstash(host=hostLogstash, port=portLogstash, minimunLevel=level.DEBUG)
extraData = {
'Field1': 'python version: ' + repr(sys.version_info),
'FieldCustom2': True,
'FieldCustom3': {'a': 1, 'b': 'c'}
}
lg.info(msg='Test Dummy', extra=extraData)
# Do Extra Logger
"""
This method was implemented for provide a easy system for create a extra logger information.
When we declare logger with logstash configuration, we can use this method.
"""
from restutil.common import Common as cm
cm().do_extra_logger(app_name='App Dummy', method_name='Method Dummy', class_name='Class Dummy',
inherited_from='Principal App Name')
# If you need add more information, you can look this other example:
cm().do_extra_logger(app_name='App Dummy', method_name='Method Dummy', class_name='Class Dummy',
inherited_from='Principal App Name', kwargs={'Result': 'Result Value Dummy'})
# Remember, For use this configuration you need have correctly configured logstash.
# logstash.conf
# input {
# udp {
# port => <listenPort. It's same that you send in request parameters>
# codec => json
# }
# }
```
- DictReader
```python
from restutil.dictionary import DictReader
import json
path = "path/to/json/file.json"
with open(path, encoding='utf-8') as json_file:
config_file = json.load(json_file)
# create DictReader object
config_dict = DictReader(config_file=config_file)
```
- make_response
```python
from restutil.encoder import make_response
from restutil.result import ResData
result: ResData = ResData()
make_response(result)
```
- Encoder
```python
from restutil.encoder import Encoder
from restutil.result import ResData
import json
result: ResData = ResData()
result.content = "test dummy"
print(json.dumps(result, cls=Encoder))
```
response = loads(dumps(result, cls=Encoder))
## Author
- Adonis Gonzalez Godoy - [LinkedIn](https://www.linkedin.com/in/adonis-gonzalez) - [E-mail](adions025@gmail.com)
Raw data
{
"_id": null,
"home_page": "https://github.com/adions025/restutil",
"name": "restutil",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Restfull,Rest,Util,Tools, Logger",
"author": "Adonis Gonzalez Godoy",
"author_email": "adions025@gmail.com",
"download_url": "https://github.com/adions025/restutil",
"platform": null,
"description": "# Rest tool\r\n> A curated list of awesome things related to microservices and computer vision.\r\n\r\nThis module contains interesting features for endpoint creation. It also includes some decorators.\r\n\r\n## Details\r\n\r\n- Decorest - class decorator that allows implementing a general try_log function in the entire function, but it is necessary to use the ResData data model\r\n\r\n## Installation\r\n\r\nUse the package manager pip to install restutil.\r\n\r\n```bash\r\npip install restutil\r\n```\r\n\r\n## Usage\r\n\r\n - Decorest\r\n```python\r\nfrom restutil.decorators import Decorest\r\n\r\n# create decorest object\r\ndeco = Decorest()\r\n\r\n# wrap foo function\r\n\r\n@deco.try_log\r\ndef foo():\r\n return None\r\n```\r\n\r\n - ResData, ResOperationType\r\n```python\r\nfrom restutil.result import ResData\r\nfrom restutil.operations import ResOperationType as resType\r\n\r\n# create ResDaata object\r\nresult: ResData = ResData()\r\n\r\n# add data in its content\r\nresult.content = \"data\"\r\n\r\n# add flagged results\r\nresult.add_result(message=str(f'Error occurred'), res_type=resType.ERROR)\r\n\r\n# check flags\r\nbool(result.has_errors)\r\n```\r\n - Logger\r\n\r\n```python\r\nfrom restutil.logger import Log\r\nfrom restutil.logger import LoggerMinimumLevel as level\r\nimport os\r\n\r\n# Setting to file\r\nlocal_path = '%s/%s' % (os.path.dirname(__file__), 'Log')\r\nlg = Log().setting_to_file(logger_path=local_path, logger_file_name='Test', minimum_level=level.DEBUG)\r\nlg.info('Test Dummy')\r\n\r\n# Setting to logstash\r\nimport sys\r\n\r\nhostLogstash = '127.0.0.1'\r\nportLogstash = 5959\r\nlg = Log().settingToLogstash(host=hostLogstash, port=portLogstash, minimunLevel=level.DEBUG)\r\nextraData = {\r\n 'Field1': 'python version: ' + repr(sys.version_info),\r\n 'FieldCustom2': True,\r\n 'FieldCustom3': {'a': 1, 'b': 'c'}\r\n}\r\nlg.info(msg='Test Dummy', extra=extraData)\r\n\r\n# Do Extra Logger\r\n\"\"\"\r\nThis method was implemented for provide a easy system for create a extra logger information. \r\nWhen we declare logger with logstash configuration, we can use this method.\r\n\"\"\"\r\n\r\n\r\n\r\nfrom restutil.common import Common as cm\r\n\r\ncm().do_extra_logger(app_name='App Dummy', method_name='Method Dummy', class_name='Class Dummy',\r\n inherited_from='Principal App Name')\r\n\r\n# If you need add more information, you can look this other example:\r\n\r\ncm().do_extra_logger(app_name='App Dummy', method_name='Method Dummy', class_name='Class Dummy',\r\n inherited_from='Principal App Name', kwargs={'Result': 'Result Value Dummy'})\r\n\r\n# Remember, For use this configuration you need have correctly configured logstash.\r\n# logstash.conf\r\n# input {\r\n# udp {\r\n# port => <listenPort. It's same that you send in request parameters>\r\n# codec => json\r\n# }\r\n# }\r\n```\r\n\r\n - DictReader\r\n```python\r\nfrom restutil.dictionary import DictReader\r\nimport json\r\n\r\npath = \"path/to/json/file.json\"\r\nwith open(path, encoding='utf-8') as json_file:\r\n config_file = json.load(json_file)\r\n \r\n# create DictReader object\r\nconfig_dict = DictReader(config_file=config_file)\r\n```\r\n\r\n - make_response\r\n```python\r\nfrom restutil.encoder import make_response\r\nfrom restutil.result import ResData\r\n\r\nresult: ResData = ResData()\r\nmake_response(result)\r\n```\r\n\r\n - Encoder\r\n```python\r\nfrom restutil.encoder import Encoder\r\nfrom restutil.result import ResData\r\nimport json\r\n\r\nresult: ResData = ResData()\r\nresult.content = \"test dummy\"\r\nprint(json.dumps(result, cls=Encoder))\r\n```\r\n\r\nresponse = loads(dumps(result, cls=Encoder))\r\n\r\n## Author\r\n\r\n- Adonis Gonzalez Godoy - [LinkedIn](https://www.linkedin.com/in/adonis-gonzalez) - [E-mail](adions025@gmail.com)\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Rest util and common tools",
"version": "1.0.13",
"project_urls": {
"Download": "https://github.com/adions025/restutil",
"Homepage": "https://github.com/adions025/restutil"
},
"split_keywords": [
"restfull",
"rest",
"util",
"tools",
" logger"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "95c3e1f66550c33dcf23a4caa127f780e817a26a70e2eeab6727af010a44a10f",
"md5": "70d3b7c1410bfa2c59a86bab4c36430c",
"sha256": "066b73796c806bcd030ce2c52c7eab47c1e357b4fac66c65db65d831d37e6069"
},
"downloads": -1,
"filename": "restutil-1.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "70d3b7c1410bfa2c59a86bab4c36430c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13516,
"upload_time": "2024-03-12T00:04:11",
"upload_time_iso_8601": "2024-03-12T00:04:11.966696Z",
"url": "https://files.pythonhosted.org/packages/95/c3/e1f66550c33dcf23a4caa127f780e817a26a70e2eeab6727af010a44a10f/restutil-1.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-12 00:04:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adions025",
"github_project": "restutil",
"github_not_found": true,
"lcname": "restutil"
}