Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions _data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,26 @@ items:
- url: /storage/byobq/
title: Bring Your Own BigQuery

- url: /storage/api/
title: Storage API
items:
- url: /storage/api/configurations/
title: Configurations
- url: /storage/api/import-export/
title: Import & Export
- url: /storage/api/importer/
title: API Importer
- url: /storage/api/tde-exporter/
title: TDE Exporter
- url: /storage/api/clients/python-client/
title: Python client
- url: /storage/api/clients/r-client/
title: R client
- url: /storage/api/clients/php-client/
title: PHP client
- url: /storage/api/clients/docker-cli/
title: Docker CLI client

- url: /transformations/
title: Transformations
items:
Expand Down
1 change: 1 addition & 0 deletions public/storage/api/async-import-handling.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/storage/api/new-table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"id","secondCol"
"1","a"
"2","b"
"3","c"
"4","d"
112 changes: 112 additions & 0 deletions src/content/docs/storage/api/clients/docker-cli/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
title: Storage Docker CLI Client
slug: 'storage/api/clients/docker-cli'
redirect_from:
- /integrate/storage/docker-cli-client/
- /integrate/storage/php-cli-client/
---


The Storage API Docker command line interface (CLI) client is a portable command line client which provides
a simple implementation of [Storage API](https://api.keboola.com/?service=storage).
It runs on any platform which has Docker installed.

Currently, the client implements

- functions for exporting and importing tables;
- functions for creating and deleting buckets; and additionally,
- the [project backup feature](/management/project-export/).

The client source is available in our [Github repository](https://github.com/keboola/storage-api-cli).
The client docker image is available in the [Quay repository](https://quay.io/repository/keboola/storage-api-cli?tab=tags).

## Running in Docker
To print available commands:

```bash
docker run quay.io/keboola/storage-api-cli:latest
```

The `latest` image tag always refers to the latest tagged version.

## Running Phar

PHAR (PHP Archive) is now deprecated, but there are still some older versions available. See the [repository documentation](https://github.com/keboola/storage-api-cli#running-phar-deprecated).

### Example --- Creating a Table
To create a new table in Storage, use the `create-table` command. Provide the name of an
existing bucket, the name of the new table and a CSV file with the table's contents.

To create the`new-table` table in the `in.c-main` bucket, use

```bash
docker run --volume=$("pwd"):/data quay.io/keboola/storage-api-cli:latest create-table in.c-main new-table /data/new-table.csv --token=storage_token
```

or on Windows:

docker run --volume=C:\Users\name\some-dir:/data quay.io/keboola/storage-api-cli:latest create-table in.c-main new-table /data/new-table.csv --token=storage_token

or when using other than the [default US region](/overview/api/#stacks-and-endpoints), you need to provide the Storage API address:

```bash
docker run --volume=$("pwd"):/data quay.io/keboola/storage-api-cli:latest create-table in.c-main new-table /data/new-table.csv --token=storage_token --url="https://connection.eu-central-1.keboola.com/"
```

Any of the above commands will import the contents of `new-table.csv` in the current directory into the newly
created table. You should see an output similar to this one:

Authorized as: ondrej.popelka@keboola.com (Odinuv Sandbox)
Bucket found ok
Table create start
Table create end
Table id: in.c-main.new-table

*Please note that the Docker container can only access folders within the container, so you need to mount a local folder.
In the example above, the local folder `$("pwd")` (replaced by the absolute path at runtime) is mounted as `/data` into the container.
The table is then accessible in this folder. The same approach applies to all other commands working with local files.*

### Example --- Importing Data
If you only want to import new data into the table, use the `write-table` command and provide
the ID (*bucketName.tableName*) of an existing table.

To import data into the `new-table` table in the `in.c-main` bucket, use

```bash
docker run --volume=$("pwd"):/data quay.io/keboola/storage-api-cli:latest write-table in.c-main.new-table /data/new-data.csv --token=storage_token --incremental
```

The above command will import the contents of the `new-data.csv` file into the existing table. If the
`--incremental` parameter is supplied, the table contents will be appended. If the parameter is not
supplied, the table contents will be overwritten. You should see an output similar to this one:

Authorized as: ondrej.popelka@keboola.com (Tutorial)
Table found ok
Import start
Import done in 17 secs.

Results:
transaction:
warnings:
importedColumns:
- id
- secondCol
totalRowsCount: 8
totalDataSizeBytes: 4096

### Example --- Exporting Data
If you want to export a table from Storage, use the `export-table` command. Provide
the ID (*bucketName.tableName*) of an existing table.

To export data from the `old-table` table in the `in.c-main` bucket, use

```bash
docker run --volume=$("pwd"):/data quay.io/keboola/storage-api-cli:latest export-table in.c-main.old-table /data/old-data.csv --token=storage_token
```

The above command will export the table from Storage and save it as `old-data.csv` in
the current directory. You should see an output similar to this one:

Authorized as: ondrej.popelka@keboola.com (Tutorial)
Table found ok
Export done in 17 secs.
153 changes: 153 additions & 0 deletions src/content/docs/storage/api/clients/php-client/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
title: Storage PHP Client Library
slug: 'storage/api/clients/php-client'
redirect_from:
- /integrate/storage/php-client/
---


The Storage API PHP client library is a portable command line client providing
the most complete [Storage API](https://api.keboola.com/?service=storage) implementation.
It runs on any platform which has PHP installed.
Currently this client implements almost all Storage API functions including, of course, exporting and importing tables.

The client source is available in our [Github repository](https://github.com/keboola/storage-api-php-client).

## Installation

The Library is available as a [Composer package](https://getcomposer.org/).
Unless you already have it, [install Composer](https://getcomposer.org/download/) on your system.
On *nix system, do so by running

```bash
curl -s https://getcomposer.org/installer | php
mv ./composer.phar ~/bin/composer # or /usr/local/bin/composer
```

On Windows, use the [installer](https://getcomposer.org/Composer-Setup.exe).

To install the library, run

```bash
composer require keboola/storage-api-client
```

in the root of your project. You should get an output similar to this one:

Using version ^18.10 for keboola/storage-api-client
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing aws/aws-sdk-php (3.18.18)
Downloading: 100%
...
- Installing keboola/storage-api-client (18.10.0)
Downloading: 100%
Writing lock file
Generating autoload files

Then add the generated autoloader in your bootstrap script:

```php
require 'vendor/autoload.php';
```

You can read more in the [Composer documentation](https://getcomposer.org/doc/01-basic-usage.md). Packages
installable by Composer can be browsed at [Packagist package repository](https://packagist.org/).

## Usage
The Storage API client is implemented as a single class. To create an instance of the class, provide a Storage API token to the
constructor.

```php
<?php

require 'vendor/autoload.php';

use Keboola\StorageApi\Client;

$client = new Client([
'token' => 'your-token',
'url' => 'https://connection.keboola.com',
]);
```

### Example --- Create a Table
To create a new table in Storage, it is recommended to use an additional
[php-csv](https://github.com/keboola/php-csv) library to work
with CSV files. The library will get installed
automatically with the Storage API client, so you can use it out of the box.
To create a new table and import CSV data in it, use the following PHP script:

```php
<?php
require 'vendor/autoload.php';

use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client;

$client = new Client([
'token' => 'your-token',
'url' => 'https://connection.keboola.com',
]);
$csvFile = new CsvFile('./new-table.csv');
$client->createTableAsync('in.c-main', 'new-table', $csvFile);
```

### Example --- Import Data
To import CSV data into an existing table and overwrite its contents, use the following PHP script:

```php
<?php
require 'vendor/autoload.php';

use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client;

$client = new Client([
'token' => 'your-token',
'url' => 'https://connection.keboola.com',
]);
$csvFile = new CsvFile('./new-table.csv');
$client->writeTableAsync('in.c-main.new-table', $csvFile);
```

### Example --- Import Data Incrementally
To import CSV data into an existing table and append the new data to the existing table contents, use the following PHP script:

```php
<?php
require 'vendor/autoload.php';

use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client;

$client = new Client([
'token' => 'your-token',
'url' => 'https://connection.keboola.com',
]);
$csvFile = new CsvFile('./new-table.csv');
$client->writeTableAsync('in.c-main.new-table', $csvFile, ['incremental' => true]);
```

All available upload options are listed in the [API documentation](https://api.keboola.com/?service=storage#post-/v2/storage/branch/-branchId-/tables/-id-/import-async).

### Example --- Export Data
To export data from a Storage table to a CSV file, use the
`TableExporter` class. It is part of the client library. You can use the following script:

```php
<?php
require 'vendor/autoload.php';

use Keboola\StorageApi\Client;
use Keboola\StorageApi\TableExporter;

$client = new Client([
'token' => 'your-token',
'url' => 'https://connection.keboola.com',
]);

$exporter = new TableExporter($client);
$exporter->exportTable('in.c-main.my-table', './old-table.csv');
```
Loading
Loading