{"id":13563999,"url":"https://github.com/frictionlessdata/tableschema-php","last_synced_at":"2025-10-18T23:32:33.123Z","repository":{"id":19581882,"uuid":"85916038","full_name":"frictionlessdata/tableschema-php","owner":"frictionlessdata","description":"A php library for working with Table Schema.","archived":false,"fork":false,"pushed_at":"2025-07-28T04:33:43.000Z","size":208,"stargazers_count":12,"open_issues_count":3,"forks_count":10,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-08-29T16:59:05.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frictionlessdata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-23T06:43:34.000Z","updated_at":"2025-07-28T04:32:08.000Z","dependencies_parsed_at":"2024-01-14T03:47:47.975Z","dependency_job_id":"195a3dd2-e6ba-4df4-a0aa-8080ca49bb8d","html_url":"https://github.com/frictionlessdata/tableschema-php","commit_stats":{"total_commits":81,"total_committers":6,"mean_commits":13.5,"dds":0.5061728395061729,"last_synced_commit":"a2e8df0995a113ee778555b8151e51b4ffe69b74"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/frictionlessdata/tableschema-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Ftableschema-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Ftableschema-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Ftableschema-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Ftableschema-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frictionlessdata","download_url":"https://codeload.github.com/frictionlessdata/tableschema-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Ftableschema-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278252440,"owners_count":25956299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:25.407Z","updated_at":"2025-10-04T01:19:41.521Z","avatar_url":"https://github.com/frictionlessdata.png","language":"PHP","readme":"# tableschema-php\n\n[![Tests](https://github.com/frictionlessdata/tableschema-php/actions/workflows/tests.yml/badge.svg)](https://github.com/frictionlessdata/tableschema-php/actions/workflows/tests.yml)\n[![Coveralls](http://img.shields.io/coveralls/frictionlessdata/tableschema-php.svg?branch=master)](https://coveralls.io/r/frictionlessdata/tableschema-php?branch=master)\n[![Scrutinizer-ci](https://scrutinizer-ci.com/g/OriHoch/tableschema-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/OriHoch/tableschema-php/)\n[![Packagist](https://img.shields.io/packagist/dm/frictionlessdata/tableschema.svg)](https://packagist.org/packages/frictionlessdata/tableschema)\n[![SemVer](https://img.shields.io/badge/versions-SemVer-brightgreen.svg)](http://semver.org/)\n[![Codebase](https://img.shields.io/badge/codebase-github-brightgreen)](https://github.com/frictionlessdata/tableschema-php)\n[![Support](https://img.shields.io/badge/support-discord-brightgreen)](https://discordapp.com/invite/Sewv6av)\n\nA utility library for working with [Table Schema](https://specs.frictionlessdata.io/table-schema/) in PHP.\n\n\n## Features summary and Usage guide\n\n### Installation\n\n```bash\n$ composer require frictionlessdata/tableschema\n```\n\n### Table\n\nTable class allows to iterate over data conforming to a table schema\n\nInstantiate a Table object based on a data source and a table schema.\n\n```php\nuse frictionlessdata\\tableschema\\Table;\n\n$table = new Table(\"tests/fixtures/data.csv\", [\"fields\" =\u003e [\n    [\"name\" =\u003e \"first_name\"],\n    [\"name\" =\u003e \"last_name\"],\n    [\"name\" =\u003e \"order\"]\n]]);\n```\n\nSchema can be any parameter valid for the Schema object (See below), so you can use a url or filename which contains the schema\n\n```php\n$table = new Table(\"tests/fixtures/data.csv\", \"tests/fixtures/data.json\");\n```\n\niterate over the data, all the values are cast and validated according to the schema\n\n```php\nforeach ($table as $row) {\n    print($row[\"order\"].\" \".$row[\"first_name\"].\" \".$row[\"last_name\"].\"\\n\");\n};\n```\n\nvalidate function will validate the schema and get some sample of the data itself to validate it as well\n \n```php\nTable::validate(new CsvDataSource(\"http://invalid.data.source/\"), $schema);\n```\n\nYou can instantiate a table object without schema, in this case the schema will be inferred automatically based on the data\n\n```php\n$table = new Table(\"tests/fixtures/data.csv\");\n$table-\u003eschema()-\u003efields();  // [\"first_name\" =\u003e StringField, \"last_name\" =\u003e StringField, \"order\" =\u003e IntegerField]\n```\n\nOptionally, specify a [CSV Dialect](https://frictionlessdata.io/specs/csv-dialect/):\n\n```php\n$table = new Table(\"tests/fixtures/data.csv\", null, [\"delimiter\" =\u003e \";\"]);\n```\n\nTable::read method allows to get all data as an array, it also supports options to modify reader behavior\n\n```php\n$table-\u003eread()  // returns all the data as an array\n```\n\nread accepts an options parameter, for example:\n\n```php\n$table-\u003eread([\"cast\" =\u003e false, \"limit\": 5])\n```\n\nThe following options are available (the values are the default values):\n\n```php\n$table-\u003eread([\n    \"keyed\" =\u003e true,  // flag to emit keyed rows\n    \"extended\" =\u003e false,  // flag to emit extended rows\n    \"cast\" =\u003e true,  //flag to disable data casting if false\n    \"limit\" =\u003e null,  // integer limit of rows to return\n]);\n```\n\nAdditional methods and functionality\n\n```php\n$table-\u003eheaders()  // [\"first_name\", \"last_name\", \"order\"]\n$table-\u003esave(\"output.csv\")  // iterate over all the rows and save the to a csv file\n$table-\u003eschema()  // get the Schema object\n$table-\u003eread()  // returns all the data as an array\n```\n\n### Schema\n\nSchema class provides helpful methods for working with a table schema and related data.\n\n`use frictionlessdata\\tableschema\\Schema;`\n\nSchema objects can be constructed using any of the following:\n\n* php array (or object)\n```php\n$schema = new Schema([\n    'fields' =\u003e [\n        [\n            'name' =\u003e 'id', 'title' =\u003e 'Identifier', 'type' =\u003e 'integer', \n            'constraints' =\u003e [\n                \"required\" =\u003e true,\n                \"minimum\" =\u003e 1,\n                \"maximum\" =\u003e 500\n            ]\n        ],\n        ['name' =\u003e 'name', 'title' =\u003e 'Name', 'type' =\u003e 'string'],\n    ],\n    'primaryKey' =\u003e 'id'\n]);\n```\n\n* string containing json\n```php\n$schema = new Schema(\"{\n    \\\"fields\\\": [\n        {\\\"name\\\": \\\"id\\\"},\n        {\\\"name\\\": \\\"height\\\", \\\"type\\\": \\\"integer\\\"}\n    ]\n}\");\n```\n\n* string containg value supported by [file_get_contents](http://php.net/manual/en/function.file-get-contents.php)\n```php\n$schema = new Schema(\"https://raw.githubusercontent.com/frictionlessdata/testsuite-extended/ecf1b2504332852cca1351657279901eca6fdbb5/datasets/synthetic/schema.json\");\n```\n\nThe schema is loaded, parsed and validated and will raise exceptions in case of any problems.\n\naccess the schema data, which is ensured to conform to the specs.\n\n```php\n$schema-\u003emissingValues(); // [\"\"]\n$schema-\u003eprimaryKey();  // [\"id\"]\n$schema-\u003eforeignKeys();  // []\n$schema-\u003efields(); // [\"id\" =\u003e IntegerField, \"name\" =\u003e StringField]\n$field = $schema-\u003efield(\"id\");  // Field object (See Field reference below)\n```\n\nvalidate function accepts the same arguemnts as the Schema constructor but returns a list of errors instead of raising exceptions\n\n```php\n// validate functions accepts the same arguments as the Schema constructor\n$validationErrors = Schema::validate(\"http://invalid.schema.json\");\nforeach ($validationErrors as $validationError) {\n    print(validationError-\u003egetMessage();\n};\n```\n\nvalidate and cast a row of data according to the schema\n\n```php\n$row = $schema-\u003ecastRow([\"id\" =\u003e \"1\", \"name\" =\u003e \"First Name\"]);\n```\n\nwill raise exception if row fails validation\n\nit returns the row with all native values\n\n```php\n$row  // [\"id\" =\u003e 1, \"name\" =\u003e \"First Name\"];\n```\n\nvalidate the row to get a list of errors\n\n```php\n$schema-\u003evalidateRow([\"id\" =\u003e \"foobar\"]);  // [\"id is not numeric\", \"name is required\" .. ]\n```\n\nInfer schema based on source data:\n\n```php\n$schema = Schema::infer(\"tests/fixtures/data.csv\");\n$table-\u003eschema()-\u003efields();  // [\"first_name\" =\u003e StringField, \"last_name\" =\u003e StringField, \"order\" =\u003e IntegerField]\n```\n\nYou can also create a new empty schema for editing\n\n```php\n$schema = new Schema();\n```\n\nset fields\n\n```php\n$schema-\u003efields([\n    \"id\" =\u003e (object)[\"type\" =\u003e \"integer\"],\n    \"name\" =\u003e (object)[\"type\" =\u003e \"string\"],\n]);\n```\n\nappropriate Field object is created according to the given descriptor (see below for Field class reference)\n\n```php\n$schema-\u003efield(\"id\");  // IntegerField object\n```\n\nadd / update or remove fields\n\n```php\n$schema-\u003efield(\"email\", [\"type\" =\u003e \"string\", \"format\" =\u003e \"email\"]);\n$schema-\u003efield(\"name\", [\"type\" =\u003e \"string\"]);\n$schema-\u003eremoveField(\"name\");\n```\n\nset or update other table schema attributes\n\n```php\n$schema-\u003eprimaryKey([\"id\"]);\n```\n\nafter every change - schema is validated and will raise Exception in case of validation errors\n\nFinally, you can get the full validated descriptor\n\n```php\n$schema-\u003efullDescriptor();\n```\n\nAnd, save it to a json file\n\n```php\n$schema-\u003esave(\"my-schema.json\");\n```\n\n### Field\n\nField class represents a single table schema field descriptor\n\nCreate a field from a descriptor\n\n```php\nuse frictionlessdata\\tableschema\\Fields\\FieldsFactory;\n$field = FieldsFactory::field([\n    \"name\" =\u003e \"id\", \"type\" =\u003e \"integer\",\n    \"constraints\" =\u003e [\"required\" =\u003e true, \"minimum\" =\u003e 5]\n]);\n```\n\nCast and validate values using the field\n\n```php\n$field-\u003ecastValue(\"3\");  // exception: value is below minimum\n$field-\u003ecastValue(\"7\");  // 7\n```\n\nAdditional method to access field data\n\n```php\n$field(\"id\")-\u003eformat();  // \"default\"\n$field(\"id\")-\u003ename();  // \"id\"\n$field(\"id\")-\u003etype(); // \"integer\"\n$field(\"id\")-\u003econstraints();  // (object)[\"required\"=\u003etrue, \"minimum\"=\u003e1, \"maximum\"=\u003e500]\n$field(\"id\")-\u003eenum();  // []\n$field(\"id\")-\u003erequired();  // true\n$field(\"id\")-\u003eunique();  // false\n$field(\"id\")-\u003etitle();  // \"Id\" (or null if not provided in descriptor)\n$field(\"id\")-\u003edescription();  // \"The ID\" (or null if not provided in descriptor)\n$field(\"id\")-\u003erdfType();  // \"http://schema.org/Thing\" (or null if not provided in descriptor)\n```\n\n## Contributing\n\nPlease read the contribution guidelines: [How to Contribute](CONTRIBUTING.md)\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Ftableschema-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrictionlessdata%2Ftableschema-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Ftableschema-php/lists"}