Package: scrippy-api
scrippy_apiREST API client for theScrippyframework (https://codeberg.org/scrippy).RequirementsPython modulesRequired modules listThe modules listed below will be automatically installed.requestsPyYAMLjsonschemaInstallationManualgitclonehttps://codeberg.org/scrippy/scrippy-api.gitcdscrippy-api
python-mpipinstall-rrequirements.txt
makeinstallWithpippipinstallscrippy-apiUsageThescrippy_api.apimodule provides theClientobject that allows querying anyREST APIuniformly using the unique methodClient.request().TheClientobject has a single methodClient.request()that accepts many parameters, most of which are optional. However, some optional parameters can become mandatory depending on the HTTP method used for the request and the use case.YMMV.TheClient.request()method always returns arequests.Responseobject (seedocumentation) that must be handled by the script.Both parameter keys and values will be automatically encoded when necessary.In case of error (HTTP code != 200), the client exits with an1return code and the error is logged ascritical.
This behavior can be inhibited during the client instantiation by setting theexit_on_errorparameter toFalse:fromscrippy_api.apiimportClientclient=Client(exit_on_error=False)In this case, any encountered errors will appear in the log file aswarning.The verification of the remote server SSL certificate can be disabled by passing the optionalverifyparameter of theClientobject toFalse:fromscrippy_api.apiimportClientclient=Client(exit_on_error=True,verify=False)Note: Disabling certificate verification is discouraged because it presents real security risks.ParametersParameters of therequestmethod of theClientobject:ParameterTypeDescriptionDefault valueparamsDictionaryApplicable to all HTTP methods. Each key/value pair will be concatenated to the URL.NonecookiesDictionaryCookies to be sent with the requestNonetimeoutintegerWaiting time before interrupting the connectionNoneheadersDictionaryHeaders to be sent with the requestNoneproxiesListList of proxy servers to use for the connectionNoneauthTupleUsername and password forBASIC AUTHauthenticationdataDictionaryData to be sent with the request. Not applicable withGETmethodNonejsonDictionaryData inJSONformat to be sent with the request. Not applicable withGETmethod. Use whendataandfileare not specifiedNonefilesDictionaryFiles to be uploaded inmultipart. The dictionary takes the form{<file name>: <file>}NoneImplemented HTTP methods:HTTP methodDescriptionGETRetrieve a resource or list of resource URIsPOSTCreate a resourcePUTReplace or create a resourcePATCHUpdate a resource or create it if non-existentDELETEDelete a resourceExamplesURL with Parametersfromscrippy_api.apiimportClientparams={"name":"Luiggi Vercotti","password":"dead/parrot"}client=Client()response=client.request(method="GET",url="https://montypython.org/user",params=params)The called URL will be:https://montypython.org/user?name=Luiggi+Vercotti&password=dead%2FparrotBasic Authentication (BASIC AUTH)Basic authentication with the following credentials:Username:Luiggi VercottiPassword:dead/parrotfromscrippy_api.apiimportClientauth=("Luiggi Vercotti","dead/parrot")client=Client()response=client.request(method="POST",url="https://montypython.org",auth=auth)Sending DataCreating theLuiggi Vercottiuser with the passworddead/parrot:fromscrippy_api.apiimportClientdata={"name":"Luiggi Vercotti","password":"dead/parrot"}client=Client()response=client.request(method="POST",url="https://montypython.org/user",data=data)File UploadUpload of the two files./images/dead_parrot.pngand./images/flying_circus.mp4:fromscrippy_api.apiimportClientfiles={"dead_parrot.png":open("./images/dead_parrot.png","rb"),"flying_circus.mp4":open("./images/flying_circus.mp4","rb")}client=Client()response=client.request(method="POST",url="https://montypython.org/upload",data=data)Resource ModificationReplaces the password of theLuiggi Vercottiuserfromscrippy_api.apiimportClientauth=("Luiggi Vercotti","dead/parrot")data={"password":"live/parrot"}params={"name":"Luiggi Vercotti"}client=Client()response=client.request(method="PATCH",url="https://montypython.org/user",params=params,data=data)File Downloadfromscrippy_api.apiimportClienturl="https://monthy.python/inquisition.zip"local_dir="/home/luiggi.vercotti"local_filename="spanish_inquisition.zip"client=Client()ifclient.download(url,local_dir,local_filename):print("No one expects the Spanish inquisition")