Previously (before 4.x) Domino had a feature to sync files from within the app but later with subsequent versions this was deprecated.
So how do users now sync files from within an app ?
By using the Python bindings for the Domino API, which is available with the python-domino library. It has a list of methods to perform functions like creation of project, list runs, etc.
The particular method we would be using in this instance is files_upload which accepts path and file as arguments.
How to set up python-domino ?
python-domino is compatible with different versions of Domino, more info on https://github.com/dominodatalab/python-domino.
python-domino is now available on PyPi. You can install with the following command:
pip install dominodatalab
Previously these Python bindings were not available in PyPi. You can also install the latest version from our Github master :
pip install https://github.com/dominodatalab/python-domino/archive/master.zip
If you are adding it in a docker file, you must add RUN to the beginning. You can also add python-domino to your requirements.txt as per below:
And to install a lower version of the library, for example 0.3.5, use the following :
pip install https://github.com/dominodatalab/python-domino/archive/0.3.5.zip
Setting up a connection to interact with your Domino deployment :
This will be done by creating a new instance of Domino :
class Domino(project, api_key=None, host=None, domino_token_file=None)
Parameter project is accepted in the form of ownerusername/projectname
How to use the files_upload method ?
files_upload which accepts path and file as arguments in the form files_upload(path,filename) is used to upload a Python file object into the specified path inside the project.
The parameters, both of which are required, are:
- path: The path to save the file to. For example,
/README.mdwill write to the root directory of the project while
/data/numbers.csvwill save the file to a subfolder named
datafolder does not yet exist, it will be created)
- file: A Python file object. For example,
f = open("authors.txt","rb")
An Example :
from domino import Domino
output_dir = "results"
# connect to domino; be sure to have these environment variables set
# (runs inside a Domino executor automatically set these for you)
domino = Domino("ownerusername/projectname",
f = open('testfile.txt', 'rb')
r = domino.files_upload("/a_new_file.txt", f)
if r.status_code == 201:
print(":) Upload successful")
print("!! Upload failed")
The app will need to run the above whenever a file is uploaded or created, even scheduled if needed but updated with the source/destination names and folders.