keboola / storage-api-client
Keboola Storage API PHP Client
Installs: 320 837
Dependents: 20
Suggesters: 0
Security: 0
Stars: 10
Watchers: 20
Forks: 8
Open Issues: 17
Requires
- php: >=8.1
- ext-json: *
- aws/aws-sdk-php: ~3.2
- google/cloud-bigquery-analyticshub: ^0.2.2
- google/cloud-storage: ^1.27
- guzzlehttp/guzzle: ~7.0
- keboola/csv: ^1
- keboola/php-datatypes: ^7.0
- microsoft/azure-storage-blob: ^1.5
- psr/log: ^1.1|^2.0|^3.0
- symfony/filesystem: ^6.0||^5.0||^4.0
- symfony/process: ^6.0||^5.0||^4.0
Requires (Dev)
- ext-curl: *
- ext-pdo: *
- ext-pdo_pgsql: *
- brianium/paratest: 2.*|6.*
- keboola/coding-standard: ^15.0
- keboola/php-csv-db-import: ^6
- keboola/phpunit-retry-annotations: ^0.5
- keboola/retry: ^0.5.0
- keboola/table-backend-utils: ^2.1
- phpcompatibility/php-compatibility: *
- phpstan/phpstan: ^1
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^7.0|^8.0|^9.0
- rector/rector: ^0.12.23
- squizlabs/php_codesniffer: ^3
- tomasfejfar/phpstan-phpunit: ^0.1.0
- dev-master
- v15.3.0
- v15.2.0
- v15.1.0
- v15.0.0
- v14.21.0
- v14.20.2
- v14.20.1
- v14.20.0
- v14.19.2
- v14.19.1
- v14.19.0
- v14.18.0
- v14.17.0
- v14.16.0
- v14.15.0
- v14.14.0
- v14.13.0
- v14.12.1
- v14.12.0
- v14.11.3
- v14.11.2
- v14.11.1
- v14.11.0
- v14.10.0
- v14.9.0
- v14.8.0
- v14.7.0
- v14.6.0
- v14.5.0
- v14.4.0
- v14.3.2
- v14.3.1
- v14.3.0
- v14.2.0
- v14.1.0
- v14.0.0
- v13.4.3
- v13.4.2
- v13.4.1
- v13.4.0
- v13.3.1
- v13.3.0
- v13.2.0
- v13.1.1
- v13.1.0
- v13.0.1
- v13.0.0
- 12.12.0
- 12.11.1
- v12.11.0
- v12.10.0
- v12.9.3
- v12.9.2
- v12.9.1
- v12.9.0
- v12.8.0
- 12.7.1
- 12.7.0
- 12.6.1
- 12.6.0
- 12.5.0
- 12.4.0
- 12.3.6
- 12.3.5
- 12.3.4
- 12.3.3
- 12.3.2
- 12.3.1
- 12.3.0
- 12.2.1
- 12.2.0
- 12.1.0
- 12.0.1
- 12.0.0
- 11.7.0
- 11.6.0
- 11.5.0
- 11.4.0
- 11.3.0
- 11.2.0
- 11.1.0
- 11.0.0
- 10.21.2
- 10.21.1
- 10.21.0
- 10.20.0
- 10.19.1
- 10.19.0
- 10.18.2
- 10.18.1
- 10.18.0
- 10.17.2
- 10.17.1
- 10.17.0
- 10.16.3
- 10.16.2
- 10.16.1
- 10.16.0
- 10.15.2
- 10.15.1
- 10.15
- 10.14.4
- 10.14.3
- 10.14.2
- 10.14.1
- 10.14
- 10.13.0
- 10.12.1
- 10.12.0
- 10.11.5
- 10.11.4
- 10.11.3
- 10.11.2
- 10.11.1
- 10.11.0
- 10.10.0
- 10.9.2
- 10.9.1
- 10.9.0
- 10.8.0
- 10.7.2
- 10.7.1
- 10.7.0
- 10.6.0
- 10.5.0
- 10.4.0
- 10.3.1
- 10.3.0
- 10.2.0
- 10.1.2
- 10.1.1
- 10.1.0
- 10.0.1
- 10.0.0
- 9.0.0
- 8.0.2
- 8.0.1
- 8.0.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.2
- 7.0.1
- 7.0.0
- 6.5.0
- 6.4.2
- 6.4.1
- 6.4.0
- 6.3.0
- 6.2.0
- 6.1.0
- 5.0.0
- 4.20.1
- 4.20.0
- 4.19.0
- 4.18.0
- 4.17.0
- 4.16.0
- 4.15.0
- 4.14.0
- 4.13.0
- 4.12.0
- 4.11.0
- 4.10.0
- 4.9.0
- 4.8.0
- 4.7.0
- 4.6.0
- 4.5.0
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.0
- 4.0.3
- 4.0.1
- 4.0.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.14.7
- 2.14.6
- 2.14.5
- 2.14.4
- 2.14.3
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.0
- 2.12.15
- 2.12.14
- 2.12.13
- 2.12.12
- 2.12.11
- 2.12.10
- 2.12.9
- 2.12.8
- 2.12.7
- 2.12.6
- 2.12.5
- 2.12.4
- 2.12.3
- 2.12.2
- 2.12.1
- 2.12.0
- 2.11.28
- 2.11.27
- 2.11.26
- 2.11.25
- 2.11.24
- 2.11.23
- 2.11.22
- 2.11.21
- 2.11.20
- 2.11.19
- 2.11.18
- 2.11.17
- 2.11.16
- 2.11.15
- 2.11.14
- 2.11.13
- 2.11.12
- 2.11.11
- 2.11.10
- 2.11.9
- 2.11.8
- 2.11.7
- 2.11.6
- 2.11.5
- 2.11.4
- 2.11.3
- 2.11.2
- 2.11.1
- 2.11.0
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.31
- 2.8.30
- 2.8.29
- 2.8.28
- 2.8.27
- 2.8.26
- 2.8.25
- 2.8.24
- 2.8.23
- 2.8.22
- 2.8.21
- 2.8.20
- 2.8.19
- 2.8.18
- 2.8.16
- 2.8.15
- 2.8.14
- 2.8.13
- 2.8.12
- 2.8.11
- 2.8.10
- 2.8.9
- 2.8.8
- 2.8.7
- 2.8.6
- 2.8.5
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.17
- 2.6.16
- 2.6.15
- 2.6.14
- 2.6.13
- 2.6.12
- 2.6.11
- 2.6.10
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.21
- 2.5.20
- 2.5.19
- 2.5.18
- 2.5.17
- 2.5.16
- 2.5.15
- 2.5.14
- 2.5.13
- 2.5.12
- 2.5.11
- 2.5.10
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.1.18
- 2.1.17
- 2.1.16
- 2.1.15
- 2.1.14
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.12.15
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-zajca-ct-1894-4
- dev-zajca-ct-1895-bq-preview-null
- dev-zajca-ct-1896-fix-tests
- dev-zajca-ct-1894-3
- dev-tomasfejfar-patch-1
- dev-vb-CT-1554-test
- dev-ondra-update-php-datatypes
- dev-zajca-ct-1026-fix-tests
- dev-miro-PST-1343-b
- dev-revert-1330-js-ct-1425-test-eb-persist-when-other-is-removed
- dev-CT-1118-null-result-in-a-non-nullable-column-when-importing-empty-value-in-csv-on-notnull-column
- dev-CT-1326-get-table-string-id-with-explode-with-limit-3
- dev-CT-1298-pridat-endpoint-na-vymazani-kose
- dev-zajca-tmp-test
- dev-BIG-204-bq-create-table-struct-invalid-length
- dev-BIG-201-bq-create-table-struct-array-without-length
- dev-BIG-205-bq-handle-value-conversion-in-data-preview
- dev-BIG-210-preview-with-typed-table-and-filters-throws-internal-error
- dev-jirka-BIG-196-propagate-permissions-to-ws
- dev-zajca-use-php81
- dev-zajca-test-native-types-timestamp
- dev-zajca-bug-types-object
- dev-client-interoperability
- dev-michaljurecko-PSGO-236
- dev-revert-1083-revert-1072-SOX-1-create-token-endpoint-for-ps-services
- dev-tf-review-1088
- dev-revert-1086-hotfix-config-no-rows-in-result
- dev-zajca-ct-1003-test
- dev-CT-996-make-sure-that-all-backends-incl-bq-td-etc-set-correct-read-only-storage-access-value
- dev-jirka-ct-887-split-suites
- dev-reduce-aws
- dev-CT-822-deprecate-all-sync-calls
- dev-KBC-2761-buckets-with-types
- dev-zajca-kbc-2903
- dev-zajca-test-synapse_fail_csas
- dev-v13.4.3-fix-sliced-gcp-upload
- dev-KBC-1445-zajca-test
- dev-KBC-2226-fix-test-testLoadUserError
- dev-wip-try-consolidate-configs
- dev-tf-inicident-3330
- dev-ujovlado-remove-versions-list-flag
- dev-KBC-1043-paratest-common-part1
- dev-dev-10.21.1-fix
- dev-bc-fix
- dev-zajca-kbc-337
- dev-zajca-kbc-994
- dev-KBC-646-automatic-datatypes-for-synapse
- dev-KBC-646-automatic-datatypes-test-for-redshift
- dev-zajca-kbc-587-phpunitupdate
- dev-KBC-254-table-display-name-in-create-endpoint
- dev-odin-KBC-229
- dev-odin-KBC-228
- dev-KBC-181-roman-fix-workspace-load-snowflake-query
- dev-tf-KBC-146-dummy-test
- dev-tf2-version-created-bug
This package is auto-updated.
Last update: 2024-12-18 19:01:50 UTC
README
Simple PHP wrapper library for Keboola Storage API.
Installation
Library is available as composer package. To start using composer in your project follow these steps:
Install composer
curl -s http://getcomposer.org/installer | php mv ./composer.phar ~/bin/composer # or /usr/local/bin/composer
Create composer.json file in your project root folder:
{ "require": { "php" : ">=8.1", "keboola/storage-api-client": "^14.0" } }
Install package:
composer install
Add autoloader in your bootstrap script:
require 'vendor/autoload.php';
Read more in Composer documentation.
Usage examples
Table write:
require 'vendor/autoload.php'; use Keboola\StorageApi\Client; use Keboola\Csv\CsvFile; $client = new Client([ 'token' => 'YOUR_TOKEN', 'url' => 'https://connection.keboola.com' ]); $csvFile = new CsvFile(__DIR__ . '/my.csv', ',', '"'); $client->writeTableAsync('in.c-main.my-table', $csvFile);
Table export to file:
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', './in.c-main.my-table.csv', []);
Tests
Warning: Never run this tests on production project with real data, always create project for testing purposes!!!
Note: For automated tests, the tests are run again three times by default if they fail. For local development this would be quite annoying,
so you can disable this by creating new file phpunit-retry.xml
from phpunit-retry.xml.dist
The main purpose of these tests is "black box" test driven development of Keboola Connection. These tests guards the API implementation.
Tests should be executed against local dockerized version of Keboola Connection (private repo).
These tests and local KBC are configured to share docker network where the Storage API and Manage API endpoints are provided.
These APIs are available at http://connection-apache/
endpoint from clients tests.
Before executing tests please install dev dependencies:
- Teradata driver download keys (AWS keys with access to
keboola-drivers
bucket):export DRIVER_DOWNLOADS_ACCESS_KEY_ID=...
export DRIVER_DOWNLOADS_SECRET_ACCESS_KEY=...
docker compose build
docker compose run --rm dev composer install
Tests are divided into multiple test suites.
Common test suite
This test suite expects following environment variables set:
STORAGE_API_URL
- URL of Keboola Storage API (https://connection.keboola.com/)STORAGE_API_TOKEN
- Storage API token associated to user (Admin master token) with all permissions. There are no special requirements for project storage backend.STORAGE_API_GUEST_TOKEN
- Storage API token associated to user (Admin master token) with guest role in same project asSTORAGE_API_TOKEN
.STORAGE_API_READ_ONLY_TOKEN
- Storage API token associated to user (Admin master token) with readOnly role in same project asSTORAGE_API_TOKEN
.STORAGE_API_SHARE_TOKEN
- Storage API token associated to user (Admin master token) with share role in same project asSTORAGE_API_TOKEN
.STORAGE_API_MAINTENANCE_URL
- URL for maintenance testing (https://maintenance-testing.keboola.com/)
You can export variables manually, or you can create and fill file set-env.sh
as copy of attached set-env.template.sh
.
Then you can run tests:
source ./set-env.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite common
Redshift backend test suite
This test suite expects following environment variables set:
STORAGE_API_URL
- URL of Keboola Storage API (https://connection.keboola.com/)STORAGE_API_TOKEN
- Storage API token associated to user (Admin master token) with all permissions. Project must haveRedshift
set as default backend.REDSHIFT_NODE_COUNT
- (optional) Set Redshift node countdefault=1
You can export variables manually, or you can create and fill file set-env.redshift.sh
as copy of attached set-env.redshift.template.sh
.
Then you can run tests:
source ./set-env.redshift.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite backend-redshift-part-1
source ./set-env.redshift.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite backend-redshift-part-2
Snowflake backend test suite
This test suite expects following environment variables set:
STORAGE_API_URL
- URL of Keboola Storage API (https://connection.keboola.com/)STORAGE_API_TOKEN
- Storage API token associated to user (Admin master token) with all permissions. Project must havesnowflake
set as default backend.
You can run these tests in docker:
source ./set-env.snowflake.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite backend-snowflake-part-1
source ./set-env.snowflake.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite backend-snowflake-part-2
Mixed backend test suite
Project can support multiple backends, this is useful for migrations from one backend to another. These tests require project with all backend assigned (redshift, snowflake).
This test suite expects following environment variables set:
STORAGE_API_URL
- URL of Keboola Storage API (https://connection.keboola.com/)STORAGE_API_TOKEN
andSTORAGE_API_LINKING_TOKEN
- Storage API token associated to user (Admin master token) with all permissions. Project must have assignedsnowflake
andredshift
backend. STORAGE_API_TOKEN and STORAGE_API_LINKING_TOKEN have to be tokens to different project in same organization.STORAGE_API_GUEST_TOKEN
- Storage API token associated to user (Admin master token) with guest role in same project asSTORAGE_API_TOKEN
.STORAGE_API_SHARE_TOKEN
- Storage API token associated to user (Admin master token) with share role in same project asSTORAGE_API_TOKEN
.STORAGE_API_MAINTENANCE_URL
- URL for maintenance testing (https://maintenance-testing.keboola.com/)STORAGE_API_TOKEN_ADMIN_2_IN_SAME_ORGANIZATION
- Storage API token associated to project in the same organization asSTORAGE_API_TOKEN
but with different admin asSTORAGE_API_TOKEN
.STORAGE_API_TOKEN_ADMIN_3_IN_OTHER_ORGANIZATION
- Storage API token associated to other admin asSTORAGE_API_TOKEN
and project in the other organization asSTORAGE_API_TOKEN
. You can export variables manually or you can create and fill fileset-env.mixed.sh
as copy of attachedset-env.mixed.template.sh
.
Then you can run tests:
source ./set-env.mixed.sh && docker compose run --rm dev vendor/bin/phpunit --testsuite backend-mixed'
Running test from PHPStorm
The whole test suite is quite big and it can take few hours. So it is a good idea to run just a testcase which you are interested in from PHPStorm, or you can run them from a console (using --filter
option).
How to set up PHPStorm for running tests:
- go to Settings / Languages & Frameworks / PHP
- row CLI -> three dots
- Plus button ->
From Docker, Vagrant, VM, WSL, Remote...
- Select
Docker Compose
; Servicedev-xdebug
; Environment variables define value from yourset-env.php
- an easy way how to do it is copy content of
set-env.php
withoutexport
prefix -> click on the icon in Env. vars. -> click on the paste icon. It should pass all the key=value entries in the window. If it doesn't work, set them manually.
- an easy way how to do it is copy content of
- Set Path mappings to
<Project root> -> /code
(<Project root>
is an absolute path to the project directory) - hint: create different interpreters for different environments
Note: see this link for more information and screenshots about the description above.
License
See LICENSE file.