API-BeispieleAPI examples
Dieser Artikel enthält Beispiele, die die Verwendung der Azure Databricks Rest-API 2,0 veranschaulichen.This article contains examples that demonstrate how to use the Azure Databricks REST API 2.0.
Ersetzen Sie in den folgenden Beispielen <databricks-instance>
durch die Arbeitsbereichs-URL Ihrer Azure Databricks-Bereitstellung.In the following examples, replace <databricks-instance>
with the workspace URL of your Azure Databricks deployment. <databricks-instance>
muss mit adb-
beginnen.<databricks-instance>
should start with adb-
. Verwenden Sie nicht die veraltete regionale URL, die mit <azure-region-name>
beginnt.Do not use the deprecated regional URL starting with <azure-region-name>
. Sie funktioniert möglicherweise nicht für neue Arbeitsbereiche, ist weniger zuverlässig und weist eine geringere Leistung als arbeitsbereichsspezifische URLs auf.It may not work for new workspaces, will be less reliable, and will exhibit lower performance than per-workspace URLs.
AuthentifizierungAuthentication
Um zu erfahren, wie Sie sich bei der Rest-API authentifizieren, überprüfen Sie die Authentifizierung mit Azure Databricks persönlichen Zugriffs Token und Authentifizieren Sie sich mithilfe Azure Active Directory Tokens.To learn how to authenticate to the REST API, review Authentication using Azure Databricks personal access tokens and Authenticate using Azure Active Directory tokens.
In den Beispielen in diesem Artikel wird davon ausgegangen, dass Sie Azure Databricks persönlichen Zugriffs Tokenverwenden.The examples in this article assume you are using Azure Databricks personal access tokens. Ersetzen Sie in den folgenden Beispielen <your-token>
durch Ihr persönliches Zugriffs Token.In the following examples, replace <your-token>
with your personal access token. curl
In den Beispielen wird davon ausgegangen, dass Sie Azure Databricks API-Anmelde Informationen unter . nettrcspeichern.The curl
examples assume that you store Azure Databricks API credentials under .netrc. In den python-Beispielen wird die Träger Authentifizierung verwendet.The Python examples use Bearer authentication. Obwohl in den Beispielen das Speichern des Tokens im Code veranschaulicht wird, damit Anmelde Informationen sicher in Azure Databricks genutzt werden können, empfiehlt es sich, das Benutzerhandbuch für die geheime Verwaltung zu befolgen.Although the examples show storing the token in the code, for leveraging credentials safely in Azure Databricks, we recommend that you follow the Secret management user guide.
Beispiele für die Verwendung von Authentifizieren mithilfe von Azure Active Directory-Token finden Siein den Artikeln in diesem Abschnitt.For examples that use Authenticate using Azure Active Directory tokens, see the articles in that section.
Eine gzip-Liste mit Clustern erhalten Get a gzipped list of clusters
curl -n -H "Accept-Encoding: gzip" https://<databricks-instance>/api/2.0/clusters/list > clusters.gz
Hoch Laden einer großen Datei in dBFS Upload a big file into DBFS
Die Menge der durch einen einzelnen API-Aufrufe hochgeladenen Daten darf nicht mehr als 1 MB betragen.The amount of data uploaded by single API call cannot exceed 1MB. Verwenden Sie die Streaming-API, die eine Kombination aus, und ist, um eine Datei hochzuladen, die größer als 1 MB ist create
addBlock
close
.To upload a file that is larger than 1MB to DBFS, use the streaming API, which is a combination of create
, addBlock
, and close
.
Im folgenden finden Sie ein Beispiel für die Durchführung dieser Aktion mithilfe von Python.Here is an example of how to perform this action using Python.
import json
import requests
import base64
DOMAIN = '<databricks-instance>'
TOKEN = '<your-token>'
BASE_URL = 'https://%s/api/2.0/dbfs/' % (DOMAIN)
def dbfs_rpc(action, body):
""" A helper function to make the DBFS API request, request/response is encoded/decoded as JSON """
response = requests.post(
BASE_URL + action,
headers={'Authorization': 'Bearer %s' % TOKEN },
json=body
)
return response.json()
# Create a handle that will be used to add blocks
handle = dbfs_rpc("create", {"path": "/temp/upload_large_file", "overwrite": "true"})['handle']
with open('/a/local/file') as f:
while True:
# A block can be at most 1MB
block = f.read(1 << 20)
if not block:
break
data = base64.standard_b64encode(block)
dbfs_rpc("add-block", {"handle": handle, "data": data})
# close the handle to finish uploading
dbfs_rpc("close", {"handle": handle})
Erstellen eines Python 3-Clusters (Databricks Runtime 5,5 LTS) Create a Python 3 cluster (Databricks Runtime 5.5 LTS)
Hinweis
Python 3 ist die Standardversion von python in Databricks Runtime 6,0 und höher.Python 3 is the default version of Python in Databricks Runtime 6.0 and above.
Im folgenden Beispiel wird gezeigt, wie ein python 3 -Cluster mithilfe der databricks-Rest-API und der HTTP-Bibliothek für HTTP- Anforderungen gestartet wird:The following example shows how to launch a Python 3 cluster using the Databricks REST API and the requests Python HTTP library:
import requests
DOMAIN = '<databricks-instance>'
TOKEN = '<your-token>'
response = requests.post(
'https://%s/api/2.0/clusters/create' % (DOMAIN),
headers={'Authorization': 'Bearer %s' % TOKEN},
json={
"cluster_name": "my-cluster",
"spark_version": "5.5.x-scala2.11",
"node_type_id": "Standard_D3_v2",
"spark_env_vars": {
"PYSPARK_PYTHON": "/databricks/python3/bin/python3",
}
}
)
if response.status_code == 200:
print(response.json()['cluster_id'])
else:
print("Error launching cluster: %s: %s" % (response.json()["error_code"], response.json()["message"]))
Erstellen eines Clusters mit hoher Parallelität Create a High Concurrency cluster
Im folgenden Beispiel wird gezeigt, wie ein Cluster mit hohem Parallelitäts Modus mithilfe der databricks-Rest-API gestartet wird:The following example shows how to launch a High Concurrency mode cluster using the Databricks REST API:
curl -n -X POST -H 'Content-Type: application/json' -d '{
"cluster_name": "high-concurrency-cluster",
"spark_version": "7.3.x-scala2.12",
"node_type_id": "Standard_D3_v2",
"spark_conf":{
"spark.databricks.cluster.profile":"serverless",
"spark.databricks.repl.allowedLanguages":"sql,python,r"
},
"custom_tags":{
"ResourceClass":"Serverless"
},
"autoscale":{
"min_workers":1,
"max_workers":2
},
"autotermination_minutes":10
}' https://<databricks-instance>/api/2.0/clusters/create
Beispiele für Jobs -API Jobs API examples
In diesem Abschnitt wird gezeigt, wie Sie Python-, Spark-Submit-und JAR-Aufträge erstellen, den JAR-Auftrag ausführen und die Ausgabe anzeigen.This section shows how to create Python, spark submit, and JAR jobs and run the JAR job and view its output.
Erstellen eines python-AuftragsCreate a Python job
Dieses Beispiel zeigt, wie ein python-Auftrag erstellt wird.This example shows how to create a Python job. Er verwendet die Apache Spark python Spark Pi-Schätzung.It uses the Apache Spark Python Spark Pi estimation.
Laden Sie die python-Datei mit dem Beispiel herunter, und laden Sie Sie mithilfe der databricks-CLIin das databricks-Datei System (dBFS) hoch.Download the Python file containing the example and upload it to Databricks File System (DBFS) using the Databricks CLI.
dbfs cp pi.py dbfs:/docs/pi.py
Erstellen des Auftrags.Create the job. In den folgenden Beispielen wird gezeigt, wie ein Auftrag mithilfe von Databricks Runtime und databricks Lighterstellt wird.The following examples demonstrate how to create a job using Databricks Runtime and Databricks Light.
Databricks RuntimeDatabricks Runtime
curl -n -X POST -H 'Content-Type: application/json' -d \ '{ "name": "SparkPi Python job", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "Standard_D3_v2", "num_workers": 2 }, "spark_python_task": { "python_file": "dbfs:/docs/pi.py", "parameters": [ "10" ] } }' https://<databricks-instance>/api/2.0/jobs/create
Databricks LightDatabricks Light
curl -n -X POST -H 'Content-Type: application/json' -d '{ "name": "SparkPi Python job", "new_cluster": { "spark_version": "apache-spark-2.4.x-scala2.11", "node_type_id": "Standard_D3_v2", "num_workers": 2 }, "spark_python_task": { "python_file": "dbfs:/docs/pi.py", "parameters": [ "10" ] } }' https://<databricks-instance>/api/2.0/jobs/create
Erstellen eines Spark-Submit -Auftrags Create a spark-submit job
Dieses Beispiel zeigt, wie ein Spark-Submit-Auftrag erstellt wird.This example shows how to create a spark-submit job. Dabei wird das Apache Spark sparkpi-Beispielverwendet.It uses the Apache Spark SparkPi example.
Laden Sie die jar -Datei mit dem Beispiel herunter, und laden Sie die JAR-Datei mithilfe der databricks-CLIin das databricks-Datei System hoch.Download the JAR containing the example and upload the JAR to Databricks File System (DBFS) using the Databricks CLI.
dbfs cp SparkPi-assembly-0.1.jar dbfs:/docs/sparkpi.jar
Erstellen des Auftrags.Create the job.
curl -n \ -X POST -H 'Content-Type: application/json' \ -d '{ "name": "SparkPi spark-submit job", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "Standard_DS3_v2", "num_workers": 2 }, "spark_submit_task": { "parameters": [ "--class", "org.apache.spark.examples.SparkPi", "dbfs:/docs/sparkpi.jar", "10" ] } }' https://<databricks-instance>/api/2.0/jobs/create
Erstellen und Ausführen eines Spark-Submit-Auftrags für R- Skripts Create and run a spark-submit job for R scripts
Dieses Beispiel zeigt, wie Sie einen Spark-Submit-Auftrag zum Ausführen von R-Skripts erstellen.This example shows how to create a spark-submit job to run R scripts.
Hochladen der R-Datei in das databricks-Datei System (dBFS) mithilfe der databricks-Befehlszeilenschnittstelle.Upload the R file to Databricks File System (DBFS) using the Databricks CLI.
dbfs cp your_code.R dbfs:/path/to/your_code.R
Wenn der Code sparkr verwendet, muss zunächst das Paket installiert werden.If the code uses SparkR, it must first install the package. Databricks Runtime enthält den sparkr-Quellcode.Databricks Runtime contains the SparkR source code. Installieren Sie das sparkr-Paket aus dem lokalen Verzeichnis, wie im folgenden Beispiel gezeigt:Install the SparkR package from its local directory as shown in the following example:
install.packages("/databricks/spark/R/pkg", repos = NULL) library(SparkR) sparkR.session() n <- nrow(createDataFrame(iris)) write.csv(n, "/dbfs/path/to/num_rows.csv")
Databricks Runtime installiert die neueste Version von sparklyr aus cran.Databricks Runtime installs the latest version of sparklyr from CRAN. Wenn im Code sparklyr verwendet wird, müssen Sie die Spark-Master-URL in angeben
spark_connect
.If the code uses sparklyr, You must specify the Spark master URL inspark_connect
. Zum bilden der Spark-Master-URL verwenden Sie dieSPARK_LOCAL_IP
Umgebungsvariable, um die IP-Adresse zu erhalten, und verwenden Sie den Standardport 7077.To form the Spark master URL, use theSPARK_LOCAL_IP
environment variable to get the IP, and use the default port 7077. Beispiel:For example:library(sparklyr) master <- paste("spark://", Sys.getenv("SPARK_LOCAL_IP"), ":7077", sep="") sc <- spark_connect(master) iris_tbl <- copy_to(sc, iris) write.csv(iris_tbl, "/dbfs/path/to/sparklyr_iris.csv")
Erstellen des Auftrags.Create the job.
curl -n \ -X POST -H 'Content-Type: application/json' \ -d '{ "name": "R script spark-submit job", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "Standard_DS3_v2", "num_workers": 2 }, "spark_submit_task": { "parameters": [ "dbfs:/path/to/your_code.R" ] } }' https://<databricks-instance>/api/2.0/jobs/create
Dadurch wird ein zurückgegeben
job-id
, das Sie dann zum Ausführen des Auftrags verwenden können.This returns ajob-id
that you can then use to run the job.Führen Sie den Auftrag mit aus
job-id
.Run the job using thejob-id
.curl -n \ -X POST -H 'Content-Type: application/json' \ -d '{ "job_id": <job-id> }' https://<databricks-instance>/api/2.0/jobs/run-now
Erstellen und Ausführen eines jar -Auftrags Create and run a JAR job
In diesem Beispiel wird gezeigt, wie ein JAR-Auftrag erstellt und ausgeführt wird.This example shows how to create and run a JAR job. Dabei wird das Apache Spark sparkpi-Beispielverwendet.It uses the Apache Spark SparkPi example.
Laden Sie die jar -Datei mit dem Beispiel herunter.Download the JAR containing the example.
Laden Sie die jar-Daten mithilfe der-API in Ihre Azure Databricks Instanz hoch:Upload the JAR to your Azure Databricks instance using the API:
curl -n \ -F filedata=@"SparkPi-assembly-0.1.jar" \ -F path="/docs/sparkpi.jar" \ -F overwrite=true \ https://<databricks-instance>/api/2.0/dbfs/put
Ein erfolgreicher Rückruf gibt zurück
{}
.A successful call returns{}
. Andernfalls wird eine Fehlermeldung angezeigt.Otherwise you will see an error message.Verschaffen Sie sich vor dem Erstellen Ihres Auftrags eine Liste aller Spark-Versionen.Get a list of all Spark versions prior to creating your job.
curl -n https://<databricks-instance>/api/2.0/clusters/spark-versions
In diesem Beispiel wird
7.3.x-scala2.12
verwendet.This example uses7.3.x-scala2.12
. Weitere Informationen zu Spark-Cluster Versionen finden Sie unter Lauf Zeit Versions Zeichenfolgen.See Runtime version strings for more information about Spark cluster versions.Erstellen des Auftrags.Create the job. Der JAR-Wert wird als Bibliothek angegeben, und in der Spark-jar-Aufgabe wird auf den Namen der Hauptklasse verwiesen.The JAR is specified as a library and the main class name is referenced in the Spark JAR task.
curl -n -X POST -H 'Content-Type: application/json' \ -d '{ "name": "SparkPi JAR job", "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "Standard_DS3_v2", "num_workers": 2 }, "libraries": [{"jar": "dbfs:/docs/sparkpi.jar"}], "spark_jar_task": { "main_class_name":"org.apache.spark.examples.SparkPi", "parameters": "10" } }' https://<databricks-instance>/api/2.0/jobs/create
Dadurch wird ein zurückgegeben
job-id
, das Sie dann zum Ausführen des Auftrags verwenden können.This returns ajob-id
that you can then use to run the job.Ausführen des Auftrags mit
run now
:Run the job usingrun now
:curl -n \ -X POST -H 'Content-Type: application/json' \ -d '{ "job_id": <job-id> }' https://<databricks-instance>/api/2.0/jobs/run-now
Navigieren Sie zu,
https://<databricks-instance>/#job/<job-id>
und Sie können sehen, dass Ihr Auftrag ausgeführt wird.Navigate tohttps://<databricks-instance>/#job/<job-id>
and you’ll be able to see your job running.Sie können Sie auch über die API überprüfen, indem Sie die von der vorherigen Anforderung zurückgegebenen Informationen verwenden.You can also check on it from the API using the information returned from the previous request.
curl -n https://<databricks-instance>/api/2.0/jobs/runs/get?run_id=<run-id> | jq
Dies sollte etwa wie folgt aussehen:Which should return something like:
{ "job_id": 35, "run_id": 30, "number_in_job": 1, "original_attempt_run_id": 30, "state": { "life_cycle_state": "TERMINATED", "result_state": "SUCCESS", "state_message": "" }, "task": { "spark_jar_task": { "jar_uri": "", "main_class_name": "org.apache.spark.examples.SparkPi", "parameters": [ "10" ], "run_as_repl": true } }, "cluster_spec": { "new_cluster": { "spark_version": "7.3.x-scala2.12", "node_type_id": "<node-type>", "enable_elastic_disk": false, "num_workers": 1 }, "libraries": [ { "jar": "dbfs:/docs/sparkpi.jar" } ] }, "cluster_instance": { "cluster_id": "0412-165350-type465", "spark_context_id": "5998195893958609953" }, "start_time": 1523552029282, "setup_duration": 211000, "execution_duration": 33000, "cleanup_duration": 2000, "trigger": "ONE_TIME", "creator_user_name": "...", "run_name": "SparkPi JAR job", "run_page_url": "<databricks-instance>/?o=3901135158661429#job/35/run/1", "run_type": "JOB_RUN" }
Um die Auftrags Ausgabe anzuzeigen, besuchen Sie die Seite Details zur Auftrags Ausführungsseite.To view the job output, visit the job run details page.
Executing command, time = 1523552263909. Pi is roughly 3.13973913973914
Erstellen eines Clusters mit aktiviertem Tabellen Zugriffs Steuerungs Beispiel Create cluster enabled for table access control example
Wenn Sie einen Cluster erstellen möchten, der für die Tabellen Zugriffs Steuerung aktiviert ist, geben Sie die folgende spark_conf
Eigenschaft im Anforderungs Text an:To create a cluster enabled for table access control, specify the following spark_conf
property in your request body:
curl -X POST https://<databricks-instance>/api/2.0/clusters/create -d'
{
"cluster_name": "my-cluster",
"spark_version": "7.3.x-scala2.12",
"node_type_id": "Standard_DS3_v2",
"spark_conf": {
"spark.databricks.acl.dfAclsEnabled":true,
"spark.databricks.repl.allowedLanguages": "python,sql"
},
"num_workers": 1,
"custom_tags":{
"costcenter":"Tags",
"applicationname":"Tags1"
}
}'
Beispiele für die Cluster Protokoll Übermittlung Cluster log delivery examples
Obwohl Sie die Spark-Treiber-und Executor-Protokolle auf der Spark-Benutzeroberfläche anzeigen können, können Azure Databricks die Protokolle auch an dBFS-Ziele übermitteln.While you can view the Spark driver and executor logs in the Spark UI, Azure Databricks can also deliver the logs to DBFS destinations. Weitere Informationen finden Sie in den folgenden Beispielen.See the following examples.
Erstellen eines Clusters mit an einen dBFS-Speicherort übermittelten ProtokollenCreate a cluster with logs delivered to a DBFS location
Der folgende curl-Befehl erstellt einen Cluster cluster_log_dbfs
mit dem Namen und fordert Azure Databricks an, die Protokolle dbfs:/logs
mit der Cluster-ID als Pfad Präfix an zu senden.The following cURL command creates a cluster named cluster_log_dbfs
and requests Azure Databricks to sends its logs to dbfs:/logs
with the cluster ID as the path prefix.
curl -n -X POST -H 'Content-Type: application/json' -d \
'{
"cluster_name": "cluster_log_dbfs",
"spark_version": "7.3.x-scala2.12",
"node_type_id": "Standard_D3_v2",
"num_workers": 1,
"cluster_log_conf": {
"dbfs": {
"destination": "dbfs:/logs"
}
}
}' https://<databricks-instance>/api/2.0/clusters/create
Die Antwort sollte die Cluster-ID enthalten:The response should contain the cluster ID:
{"cluster_id":"1111-223344-abc55"}
Nach der Cluster Erstellung Azure Databricks alle fünf minutenprotokoll Dateien mit dem Ziel synchronisiert.After cluster creation, Azure Databricks syncs log files to the destination every 5 minutes.
Es lädt Treiber Protokolle in dbfs:/logs/1111-223344-abc55/driver
und Executor-Protokolle in hoch dbfs:/logs/1111-223344-abc55/executor
.It uploads driver logs to dbfs:/logs/1111-223344-abc55/driver
and executor logs to dbfs:/logs/1111-223344-abc55/executor
.
Überprüfen des Status der Protokoll ÜbermittlungCheck log delivery status
Sie können Cluster Informationen mit dem Status der Protokoll Übermittlung über API abrufen:You can retrieve cluster information with log delivery status via API:
curl -n -H 'Content-Type: application/json' -d \
'{
"cluster_id": "1111-223344-abc55"
}' https://<databricks-instance>/api/2.0/clusters/get
Wenn der letzte Batch des Protokoll Uploads erfolgreich war, sollte die Antwort nur den Zeitstempel des letzten Versuchs enthalten:If the latest batch of log upload was successful, the response should contain only the timestamp of the last attempt:
{
"cluster_log_status": {
"last_attempted": 1479338561
}
}
Wenn Fehler auftreten, wird die Fehlermeldung in der Antwort angezeigt:In case of errors, the error message would appear in the response:
{
"cluster_log_status": {
"last_attempted": 1479338561,
"last_exception": "Exception: Access Denied ..."
}
}
Arbeitsbereichs Beispiele Workspace examples
Im folgenden finden Sie einige Beispiele für die Verwendung der Arbeitsbereichs-API zum Auflisten, zum Erstellen, löschen, exportieren und Importieren von Arbeitsbereichs Objekten.Here are some examples for using the Workspace API to list, get info about, create, delete, export, and import workspace objects.
Auflisten eines Notebooks oder OrdnersList a notebook or a folder
Der folgende curl-Befehl listet einen Pfad im Arbeitsbereich auf.The following cURL command lists a path in the workspace.
curl -n -X GET -H 'Content-Type: application/json' -d \
'{
"path": "/Users/user@example.com/"
}' https://<databricks-instance>/api/2.0/workspace/list
Die Antwort sollte eine Liste von Status enthalten:The response should contain a list of statuses:
{
"objects": [
{
"object_type": "DIRECTORY",
"path": "/Users/user@example.com/folder"
},
{
"object_type": "NOTEBOOK",
"language": "PYTHON",
"path": "/Users/user@example.com/notebook1"
},
{
"object_type": "NOTEBOOK",
"language": "SCALA",
"path": "/Users/user@example.com/notebook2"
}
]
}
Wenn der Pfad ein Notebook ist, enthält die Antwort ein Array mit dem Status des Eingabe Notebooks.If the path is a notebook, the response contains an array containing the status of the input notebook.
Informationen zu einem Notebook oder OrdnerGet information about a notebook or a folder
Der folgende curl-Befehl ruft den Status eines Pfads im Arbeitsbereich ab.The following cURL command gets the status of a path in the workspace.
curl -n -X GET -H 'Content-Type: application/json' -d \
'{
"path": "/Users/user@example.com/"
}' https://<databricks-instance>/api/2.0/workspace/get-status
Die Antwort sollte den Status des Eingabe Pfads enthalten:The response should contain the status of the input path:
{
"object_type": "DIRECTORY",
"path": "/Users/user@example.com"
}
Erstellen eines OrdnersCreate a folder
Der folgende curl-Befehl erstellt einen Ordner.The following cURL command creates a folder. Der Ordner wird rekursiv wie erstellt mkdir -p
.It creates the folder recursively like mkdir -p
.
Wenn der Ordner bereits vorhanden ist, führt er keine Aktionen aus.If the folder already exists, it will do nothing and succeed.
curl -n -X POST -H 'Content-Type: application/json' -d \
'{
"path": "/Users/user@example.com/new/folder"
}' https://<databricks-instance>/api/2.0/workspace/mkdirs
Wenn die Anforderung erfolgreich ist, wird eine leere JSON-Zeichenfolge zurückgegeben.If the request succeeds, an empty JSON string will be returned.
Löschen eines Notebooks oder OrdnersDelete a notebook or folder
Der folgende curl-Befehl löscht ein Notebook oder einen Ordner.The following cURL command deletes a notebook or folder. Sie können aktivieren recursive
, um einen nicht leeren Ordner rekursiv zu löschen.You can enable recursive
to recursively delete a non-empty folder.
curl -n -X POST -H 'Content-Type: application/json' -d \
'{
"path": "/Users/user@example.com/new/folder",
"recursive": "false"
}' https://<databricks-instance>/api/2.0/workspace/delete
Wenn die Anforderung erfolgreich ist, wird eine leere JSON-Zeichenfolge zurückgegeben.If the request succeeds, an empty JSON string is returned.
Exportieren eines Notebooks oder Ordners Export a notebook or folder
Der folgende curl-Befehl exportiert ein Notebook.The following cURL command exports a notebook. Notebooks können in den folgenden Formaten exportiert werden: SOURCE
, HTML
, JUPYTER
, DBC
.Notebooks can be exported in the following formats: SOURCE
, HTML
, JUPYTER
, DBC
. Ein Ordner kann nur als exportiert werden DBC
.A folder can be exported only as DBC
.
curl -n -X GET -H 'Content-Type: application/json' \
'{
"path": "/Users/user@example.com/notebook",
"format": "SOURCE"
}' https://<databricks-instance>/api/2.0/workspace/export
Die Antwort enthält Base64-codierten Notebook-Inhalt.The response contains base64 encoded notebook content.
{
"content": "Ly8gRGF0YWJyaWNrcyBub3RlYm9vayBzb3VyY2UKcHJpbnQoImhlbGxvLCB3b3JsZCIpCgovLyBDT01NQU5EIC0tLS0tLS0tLS0KCg=="
}
Alternativ können Sie das exportierte Notebook direkt herunterladen.Alternatively, you can download the exported notebook directly.
curl -n -X GET "https://<databricks-instance>/api/2.0/workspace/export?format=SOURCE&direct_download=true&path=/Users/user@example.com/notebook"
Die Antwort ist der Inhalt des exportierten Notebooks.The response will be the exported notebook content.
Importieren eines Notebooks oder Verzeichnisses Import a notebook or directory
Der folgende curl-Befehl importiert ein Notebook in den Arbeitsbereich.The following cURL command imports a notebook in the workspace. Mehrere Formate ( SOURCE
, HTML
, JUPYTER
, DBC
) werden unterstützt.Multiple formats (SOURCE
, HTML
, JUPYTER
, DBC
) are supported.
Wenn den format
Wert SOURCE
hat, müssen Sie angeben language
.If the format
is SOURCE
, you must specify language
. Der- content
Parameter enthält Base64-codierten Notebook-Inhalt.The content
parameter contains base64 encoded notebook content. Sie können aktivieren overwrite
, um das vorhandene Notebook zu überschreiben.You can enable overwrite
to overwrite the existing notebook.
curl -n -X POST -H 'Content-Type: application/json' -d \
'{
"path": "/Users/user@example.com/new-notebook",
"format": "SOURCE",
"language": "SCALA",
"content": "Ly8gRGF0YWJyaWNrcyBub3RlYm9vayBzb3VyY2UKcHJpbnQoImhlbGxvLCB3b3JsZCIpCgovLyBDT01NQU5EIC0tLS0tLS0tLS0KCg==",
"overwrite": "false"
}' https://<databricks-instance>/api/2.0/workspace/import
Wenn die Anforderung erfolgreich ist, wird eine leere JSON-Zeichenfolge zurückgegeben.If the request succeeds, an empty JSON string is returned.
Alternativ können Sie ein Notebook per mehrteiligen Formular Bereitstellung importieren.Alternatively, you can import a notebook via multipart form post.
curl -n -X POST https://<databricks-instance>/api/2.0/workspace/import \
-F path="/Users/user@example.com/new-notebook" -F format=SOURCE -F language=SCALA -F overwrite=true -F content=@notebook.scala