Package: cloudofficeprint
cloudofficeprint-pythonThis project provides a Python interface for Cloud Office Print.InstallationTo install the Cloud Office Print Python package, you can type in your terminal:pip install cloudofficeprintUsageCreate a template (docx, xlsx, pptx, HTML, md, txt, csv), for the possible tags, clickhere.Create the input data with this Python SDKSend template and data to a Cloud Office Print server and save the response to a file with this Python SDKTo see the JSON-data that is sent to the Cloud Office Print server, you can turn on verbose-mode by setting the argumentcop_verbosetoTruewhen creating aPrintJob.Quickstart: Hello World exampleTemplate (docx)DataThe data can be generated by the Python SDK:importcloudofficeprintascop# Main object that holds the datacollection=cop.elements.ElementCollection()# Create the title element and add it to the element collectiontitle=cop.elements.Property(name='title',value='Hello World!')collection.add(title)# Create the text element and add it to the element collectiontext=cop.elements.Property(name='text',value='This is an example created with the Cloud Office Print Python SDK')collection.add(text)...Cloud Office Print serverThe template and the data need to be sent to a Cloud Office Print server that merges both. This can be done by setting up the configuration for a Cloud Office Print server and passing it to the print job instance. You can get your API key by signing up athttps://www.cloudofficeprint.com....SERVER_URL="https://api.cloudofficeprint.com/"API_KEY="YOUR_API_KEY"# Replace by your own API key# Add serverserver=cop.config.Server(SERVER_URL,cop.config.ServerConfig(api_key=API_KEY))# Create print jobprintjob=cop.PrintJob(data=collection,server=server,template=cop.Resource.from_local_file('PATH_TO_TEMPLATE_FILE'),)# Execute print job and save response to fileresponse=printjob.execute()response.to_file('PATH_OF_OUTPUT_FILE')wherePATH_TO_TEMPLATE_FILEis the (relative) path to your template file (e.g../data/template.docx) andPATH_OF_OUTPUT_FILEis the (relative) path where you want the output file to be stored (e.g../output/output_file).ResultOther examplesGoing through the other examples is also recommended as this gives you a good idea on how to use the SDK. The current examples are:order_confirmation_example.pypdfsignature_example.pysolar_system_example.pyspacex_example.py (the most extensive example)multiple_request_merge_example.pyThe examples can be found in the parent directory of the project onGithub. Each example also has its own folder containing the used templates, the generated output files and a markdown file with explanation.DocumentationThe documentation for this SDK can be found inside thedocs/cloudofficeprint/folder onGithub. Open the index.html file in a browser.The documentation for Cloud Office Print can be found at theCloud Office Print docs.DevelopmentDocumentationTo generate the documentation, you can run the following command (after installing pdoc:pip install pdoc3) in the project directory:pdoc--html--force--output-dirdocs/cloudofficeprint/pdocis used for documentation generation.
Things to keep in mind when writing docs (some of these are non-standard):Docstrings are inherited fromsuper().Instance variables (attributes) can have docstrings, start the docstring on the lineunderneaththe attributeFor@propertyproperties, the setter's documentation is ignored. Make sure everything is in the getter.You can use markdown in the docstrings, along with the generated google-style docs.Doing something like `ClassName` (with backticks, which are generally for inline code) makes pdoc look for the reference and try to hyperlink it in the generated docs.This works with any object, useful methods or instance variables of a class too.TestsThere are tests for all classes and methods. The tests check if the JSON that needs to be sent to the server is as expected. To run the tests:Open a terminal in the parent directory of this project, which can be found onGithub.Type in the terminal:pythontest.pyThe tests succeeded if nothing is printed to the terminalUseful Visual Studio Code extensionsnjpwerner.autodocstring: Python docstring generator, uses Google-style docs by default.PublishingTo publish this project toPyPI, follow these steps:Create an account on PyPI.Install theTwine utilityby typing in your terminal:pipinstalltwineIn the parent directory, type in your terminal:pythonsetup.pysdistbdist_wheelCheck if the building succeeded (PASSED):twinecheckdist/*Upload to PyPI:twineuploaddist/*More information can be foundhere.