2017 © Pedro Peláez
 

library datapackage

A utility library for working with Data Packages

image

frictionlessdata/datapackage

A utility library for working with Data Packages

  • Tuesday, January 23, 2018
  • by OriHoch
  • Repository
  • 8 Watchers
  • 6 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 11 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

Data Package

Build Coveralls Scrutinizer-ci Packagist SemVer Codebase Support, (*1)

A utility library for working with Data Package in PHP., (*2)

Features summary and Usage guide

Installation

composer require frictionlessdata/datapackage

Optionally, to create zip files you will need the PHP zip extension. On Ubuntu it can be enabled with sudo apt-get install php-zip, (*3)

Package

Load a data package conforming to the specs, (*4)

use frictionlessdata\datapackage\Package;
$package = Package::load("tests/fixtures/multi_data_datapackage.json");

Iterate over the resources and the data, (*5)

foreach ($package as $resource) {
    echo $resource->name();
    foreach ($resource as $row) {
        echo $row;
    }
}

Get all the data as an array (loads all the data into memory, not recommended for large data sets), (*6)

foreach ($package as $resource) {
    var_dump($resource->read());
}

All data and schemas are validated and throws exceptions in case of any problems., (*7)

Validate the data explicitly and get a list of errors, (*8)

Package::validate("tests/fixtures/simple_invalid_datapackage.json");  // array of validation errors

Load a zip file, (*9)

$package = Package::load('http://datahub.io/opendatafortaxjustice/eucountrydatawb/r/datapackage_zip.zip');

Provide read options which are passed through to tableschema-php Table::read method, (*10)

$package = Package::load('http://datahub.io/opendatafortaxjustice/eucountrydatawb/r/datapackage_zip.zip');
foreach ($package as $resource) {
    $resource->read(["cast" => false]);
}

The package object has some useful methods to access and manipulate the resources, (*11)

$package = Package::load("tests/fixtures/multi_data_datapackage.json");
$package->resources();  // array of resource name => Resource object (see below for Resource class reference)
$package->getResource("first-resource");  // Resource object matching the given name
$package->removeResource("first-resource");
// add a tabular resource
$package->addResource("tabular-resource-name", [
    "profile" => "tabular-data-resource",
    "schema" => [
        "fields" => [
            ["name" => "id", "type" => "integer"],
            ["name" => "name", "type" => "string"]
        ]
    ],
    "path" => [
        "tests/fixtures/simple_tabular_data.csv",
    ]
]);

Create a new package from scratch, (*12)

$package = Package::create([
    "name" => "datapackage-name",
    "profile" => "tabular-data-package"
]);
// add a resource
$package->addResource("resource-name", [
    "profile" => "tabular-data-resource", 
    "schema" => [
        "fields" => [
            ["name" => "id", "type" => "integer"],
            ["name" => "name", "type" => "string"]
        ]
    ],
    "path" => "tests/fixtures/simple_tabular_data.csv"
]);
// save the package descriptor to a file
$package->saveDescriptor("datapackage.json");

Save the entire datapackage including any local data to a zip file, (*13)

$package->save("datapackage.zip");

Resource

Resource objects can be accessed from a Package as described above, (*14)

$resource = $package->getResource("resource-name")

or instantiated directly, (*15)

use frictionlessdata\datapackage\Resource;
$resource = Resource::create([
    "name" => "my-resource",
    "profile" => "tabular-data-resource",
    "path" => "tests/fixtures/simple_tabular_data.csv",
    "schema" => ["fields" => [["name" => "id", "type" => "integer"], ["name" => "name", "type" => "string"]]]
]);

Iterating or reading over the resource produces combined rows from all the path or data elements, (*16)

foreach ($resource as $row) {};  // iterating
$resource->read();  // get all the data as an array

Contributing

Please read the contribution guidelines: How to Contribute, (*17)

The Versions

23/01 2018

dev-master

9999999-dev

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

30/11 2017

v0.1.9

0.1.9.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

21/11 2017

v0.1.7

0.1.7.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

30/08 2017

v0.1.5

0.1.5.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

31/07 2017

v0.1.4

0.1.4.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

15/06 2017

v0.1.3

0.1.3.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2017

v0.1.2

0.1.2.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

18/04 2017

v0.1.1

0.1.1.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

 

The Development Requires

17/04 2017

v0.1.0

0.1.0.0

A utility library for working with Data Packages

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires