API Documentation
File
knps.File(filename)File wrapper class. This wrapper class should be used when storing a file into a KGPLValue object.
Parameters
filenameThe absolute or relative path to the file .
Example
import knps
file = knps.File("picture.png")
kgplvalue = knps.create_values(file, "a picture")
KGPLValue
knps.KGPLValue(val, comment, user='anonymous', dependency=[], vid=None, verbose=False)Python representation of a KGPLValue. Users should not user the constructor to create a KGPLValue object directly. Instead, use the create_value function described below.
Parameters
valThe concrete value stored in the KGPLValue object.commentA user-readable comment (of typestr) associated with this KGPLValue object.userUsername of the owner of the KGPLValue object.dependencyA list consisting of the KGPL objects that this KGPLValue depended on.vidThe unique identifier assigned by the server.verboseIf set to true, more information is produced in the terminal. Otherwise, a succint description is printed when the construction succeeds.
getVid(self)Return the vid
getConcreteVal(self)Return the concrete value
create_label(self, label, comment)Create a label to refer to this KGPLValue.
Parameters
labelA label (of typestr) identifier for the value. Consider use label as acommentDescriptive comment for the label creation
Return
The KGPLVariable object that underlies the label
update_label(self, label, new_comment)Update the input label with this KGPLValue
Parameters
labelThe label to be updatedcommentDescriptive comment for the label update
Return
The KGPLVariable object that underlies the label
KGPLVariable
knps.KGPLVariable(val_id, comment, vid, user='anonymous', timestamp=None)Python representation of a KGPLVariable. Users should not user the constructor to create a KGPLVariable object directly. Instead, use the variable function described below.
Parameters
val_idThe vid of the KGPLValue to be storedcommentA user-readable comment (of typestr) associated with this KGPLVariable object.vidThe unique identifier assigned by the server.userUsername of the owner of the KGPLVariable object.timestampTimestamp of the variable creation
getVid(self)Get the vid
Return
- the vid of this KGPLVariable.
getValid(self)Get the vid of the contained KGPLValue
Return
- the vid of the KGPLValue this variable refers to.
refresh(self)Synchronize with the server to get the newest state of the variable in case of users work on the same variable concurrently.
getConcreteVal(self)Get the KGPLValue stored in this KGPLVariable object
Return
- The KGPLValue object stored in this variable
API Methods
knps.kgplcreate_value(val, comment, user='anonymous', dependency=[], verbose=False)Create a KGPLValue based on the inputs and publish to the server.
Parameter
- 'val'
Concrete value to store (We currently support the following types:
int,float,bool,list,dict,File,pandas.DataFrame,Relation) - 'comment'
A human readable comment (of type
str) associated with the value creattion - 'user'
User name of the owner of the KGPLValue, the default value is
anonymous dependencyA list consisting of the KGPL objects that this KGPLValue depended on. Each element in the list can be one of the three types:KGPLValue,KGPLVariableorLabel. The default value is empty list.verbose: If set to true, more information is produced in the terminal. Otherwise, a succint description is printed when the construction succeeds. The default value isFalse.
Return
A KGPLValue object constructed based on inputs
publish_new(val, comment, label=None, user='anonymous', dependency=[], verbose=False, label_comment='')Create a KGPLValue based on the inputs and publish to the server, then create and return a label for this KGPLValue.
Parameter
valConcrete value to store (We currently support the following types:int,float,bool,list,dict,File,pandas.DataFrame,Relation)commentA human readable comment (of typestr) associated with the value creationlabelA human readable name to refer to the new KGPLValue. The default value isNone. In that case, a default label is generated by the server.userUser name of the owner of this operation, the default value isanonymousdependencyA list consisting of the KGPL objects that this KGPLValue depended on. Each element in the list can be one of the three types:KGPLValue,KGPLVariableorLabel. The default value is empty list.verbose: If set to true, more information is produced in the terminal. Otherwise, a succint description is printed when the construction succeeds. The default value isFalse.- 'label_comment'
A human readable comment (of type
str) associated with the label creation
Return
A KGPLVariable object constructed based on inputs
load_val(vid)Fetch the KGPLValue of the corresponding vid
Parameter
vidThe vid of the desired KGPLValue
Return
A KGPLValue object
publish_update(val, comment, label, user='anonymous', dependency=[], verbose=False, label_comment='')Create a KGPLValue based on the inputs and publish to the server, then update and return the label for this KGPLValue.
Parameter
valConcrete value to store (We currently support the following types:int,float,bool,list,dict,File,pandas.DataFrame,Relation)commentA human readable comment (of typestr) associated with the value creationlabelThe label being updateduserUser name of the owner of this operation, the default value isanonymousdependencyA list consisting of the KGPL objects that this KGPLValue depended on. Each element in the list can be one of the three types:KGPLValue,KGPLVariableorLabel. The default value is empty list.verbose: If set to true, more information is produced in the terminal. Otherwise, a succint description is printed when the construction succeeds. The default value isFalse.- 'label_comment'
A human readable comment (of type
str) associated with the label update
Return
A KGPLVariable object updated based on inputs
get_label_content(label)Get the content underlying a label
Parameter
labelThe label being fetched
Return
A KGPLVariable object this label represents
get_history(kg_var)Fetch the history information of a KGPLVariable object from server
Parameter
kg_var: KGPLVariable object whose history information is of interest
Return
A list of vids this variable has refered to. The first element is the newest state while the last element is the oldest state.
check_label_occupied(vid)Check the server to determine if the label is occupied.
Parameter
vidThe label name to check
changeNamespace(new_url)change the namespace of the current program.
Parameter
new_url
the new namespace
viewNamespace()print the current namespace