Result For Utility Tools
Project description
Result4Utility, easy to use, fast to implement, ready for production
The module contains interesting features for APIs endpoint creation. With some interesting decorators.
Documentation: https://github.com/luigi-dv/result4utility
Source Code: https://github.com/luigi-dv/result4utility
Installation
pip install result4utility
Examples
Result
A Structure for dynamics models to encapsulate values.
When select an Error result type, the property HasErrors take true value.
Use Case:
from result4utility.result import Result
from result4utility.result import ResultOperationType as resultType
# Initialize the Result Class
response = Result()
# Declare the model
model = {'User':'john.doe', 'Name':'John', 'Surname':'Doe'}
# Setting up the value of the response content with the model
response.content = model
# Adding results to our created response
response.add_result(message='Successfully Request', result_type=resultType.SUCCESS)
Reader
This class provides a dictionary reader functionality using attributes.
Use Case:
from result4utility.dictionary import Reader
# Declare the dictionary to read
dictionary_test = {
"primary_entry":"primary test data",
"secondary_entry" : {
"secondary_entry_1":"secondary test data 1",
"secondary_entry_2":{
"secondary_entry_2_1":"secondary test data 2.1",
}
}
}
# Setting up the Reader Object
dictionary = Reader(config_file=dictionary_test)
# Read the values
test_1 = dictionary.primary_entry.get()
test_2 = dictionary.secondary_entry.secondary_entry_2.secondary_entry_2_1.get()
# Print the values
print(test_1)
print(test_2)
Tools
Two methods for dictionary operations.
Convert from object to dictionary:
from result4utility.tools import Tools
class Test(object):
index:int
name:str
def __init__(self, index_input:int, name_input:str):
self.index=index_input
self.name=name_input
# Define the object to test
object_test:object = Test(1,'John')
# Initialize the Tool class
tool = Tools()
# Convert the Object to Dictionary
result:dict = tool.dictionary_from_object(model=object_test)
# Output
print ({'index':1, 'name':'John'})
As you can see we are doing the object conversion over a new initialized object. Operations will not take actions over your main Objects.
Remove properties of dictionary:
from result4utility.tools import Tools
class Test(object):
index:int
name2:str
def __init__(self, index_input:int, name_input:str):
self.index=index_input
self.name=name_input
# Initialize the Tool class
tool = Tools()
# Create new Test Class Object
object_test:object = Test(1,'John')
# Convert the Object to Dictionary
dictionary_test:dict = tool.dictionary_from_object(model=Test)
# Remove the dictionary property
result:dict = tool.remove_property(target=dictionary_test, props=['index'])
# Output
print({'name':'John'})
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
File details
Details for the file result4utility-0.1.3.tar.gz
.
File metadata
- Download URL: result4utility-0.1.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d609bb60ca73a364ebe20088abdfb57a5a45bda7cc5093647aa35db34e3ff03 |
|
MD5 | c0937992d961c469284bc7f1177eca0c |
|
BLAKE2b-256 | 5ef882bbd6bc1def54c7ac5fde444d6ff921e5e74b256451041c93715df7eaac |