Package: falconlib
falconlibPython client lib for accessing Falcon APIPurpose•Installation•Notes•Document Management•AuthorPurposeFalconlibis the preferred means of accessing my back-end services. With the proper credentials,
you can access some of those back-end services through therequestspacakge, but they change
frequently and move from endpoint to endpoint.Falconlibsmoothes out those developmental
undulations.GETTING STARTEDInstallationpip install falconlibInstantiationfromfalconlibimportFalconlLibfalconlib=FalconLib('https://your-endpoint.com')falconlib.authorize('my_username','my_password')NOTESTherequestspackage handles the HTTPS traffic betweenfalconliband the back-end services.
Because of that, you can access the lastresponseobject thus:r=falconlib.last_responseHTTP STATUS CODESIf an API call fails, the HTTP status code will be one of these:Status CodeExplanation401Invalid login credentials404Object not found, e.g. Document, Tracker, etc.409Conflict. Check falconlib.last_response.json() for a specific explanation500Server-side error. Sorry about that.FUNCTION RETURNSAll functions return a FalconStatus object having these fields:FieldTypeValuesuccess(bool)True if successful otherwise Falsestatus(int)HTTP status of last HTTP(s) requestmessage(str)Message that explains the success or failure of the function callpayload(dict)Contains the payload of the function call and is documented with each method belowDOCUMENT MANAGEMENTAdd a document to the databaseadd_document(doc: dict) -> FalconStatusArgumentsdoc(dict) - Elements of aDocumentResultInstance ofFalconStatusExamplefromfalconlibimportFalconlLibfalconlib=FalconLib('https://your-endpoint.com')falconlib.authorize('my_username','my_password')DOC_1={"id":"doc-1","path":"x:\\shared\\office\\user\\client\\discovery\\our production\\my_document.pdf","filename":"my_document.pdf","type":"application/pdf","title":"my_document","create_date":"07/01/2022","document_date":"07/15/2022","beginning_bates":"TD002304","ending_bates":"TD002304","page_count":1,"client_reference":"20202.1",}fstatus=falconlib.add_document(DOC_1)assertfstatus.success==Trueassertfalconlib.last_response.status_code==201Retrieve a Document from the Databaseget_document(document_id: str, path: str) -> FalconStatusArgumentsdocument_id (str):idof the document to be retrieved. (optional)
path (str):pathof the document to be retrieved. (optional)You must provideeitheradocument_idor apath. If you provide both, thendocument_idwill be used. If you provide neither, the call will raise an exception.ResultInstance ofFalconStatuswhere thepayloadfield contains adicthaving the elements of aDocumentExamplefromfalconlibimportFalconlLibfalconlib=FalconLib('https://your-endpoint.com')falconlib.authorize('my_username','my_password')doc=falconlib.get_document('doc-1').payloadassertfalconlib.last_response.status_code==200assertdoc['id']=='doc-1'Update a Document in the Databaseupdate_document(revised_doc: dict) -> FalconStatusArgumentsrevised_doc(dict) - Elements of aDocumentResultInstance ofFalconStatusExamplefromfalconlibimportFalconlLibfalconlib=FalconLib('https://your-endpoint.com')falconlib.authorize('my_username','my_password')# Retrieve document before updating to avoid version conflicts.revised_doc=falconlib.get_document(DOC_1['id']).payload# Update the field(s) you want to revise.revised_doc['title']='**Updated Document'# Update the documentr=falconlib.update_document(revised_doc)assertr.success==Trueassertfalconlib.last_response.status_code==200Delete a Document from the Databasedelete_document(document_id: str, cascade: bool = True) -> FalconStatusArgumentsdocument_id: (str) - ID of document to delete. (required)cascade(bool) - Whether to cascade the delete. (optional, default=True)
Ifcascadeis set to True, then the document will be deleted and removed from all trackers
that reference it. Ifcascadeis set to False, then the document will be deleted only if
it is not linked to any trackers.fromfalconlibimportFalconlLibfalconlib=FalconLib('https://your-endpoint.com')r=falconlib.authorize('my_username','my_password')r=falconlib.delete_document(document_id=DOC_1['id'],cascade=False)assertr.success==Trueassertfalconlib.last_response.status_code==200TRACKER MANAGEMENTMAINTENANCEBefore posting a new version, run pytest and make sure all tests are passing.Next, make sure to bump the version in falconlib.tomlThen, build a new version:py -m buildFinally, upload the new version:py -m twine upload dist/*NOTE:
For the upload, yourusername is__token__password is a project-scoped tokenOn Windows, youcannotuseCTRL-Vto paste the project-scoped token. YouMUSTright click the command shell window and selectEdit->Paste.For detailed instructions, visit (https://packaging.python.org)[https://packaging.python.org/en/latest/tutorials/packaging-projects/].AuthorThomas J. Daley, J.D. is an active, board certified family law litigation attorney practicing primarily in Collin County, Texas and software developer. My family law practice is limited to divorce, child custody, child support, enforcment, and modification suits.Web Site