{"id":9640,"library":"datapackage","title":"Data Package","description":"The `datapackage-py` library is a Python implementation of the Data Package standard, focusing on utilities to create, read, and validate data packages as defined by frictionlessdata.io specifications. It provides a simple API for interacting with `datapackage.json` files and their associated resources. The current version is 1.15.4, and it follows a minor release cadence as needed for bug fixes and small enhancements.","status":"active","version":"1.15.4","language":"en","source_language":"en","source_url":"https://github.com/frictionlessdata/datapackage-py","tags":["data package","frictionless data","data standard","metadata","data validation"],"install":[{"cmd":"pip install datapackage","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Provides core validation capabilities for data packages and their resources.","package":"goodtables-py","optional":false},{"reason":"Handles HTTP requests for remote data packages and resources.","package":"requests","optional":false}],"imports":[{"symbol":"Package","correct":"from datapackage import Package"},{"symbol":"Resource","correct":"from datapackage import Resource"},{"note":"ValidationError is directly available from the top-level package, though it originates from `datapackage.exceptions` internally.","wrong":"from datapackage.exceptions import ValidationError","symbol":"ValidationError","correct":"from datapackage import ValidationError"}],"quickstart":{"code":"from datapackage import Package, Resource\nimport json\nimport os\n\n# Create a simple data package descriptor in memory\ndescriptor = {\n    'name': 'my-data-package',\n    'resources': [\n        {\n            'name': 'cities',\n            'path': 'cities.csv',\n            'profile': 'tabular-data-resource',\n            'schema': {\n                'fields': [\n                    {'name': 'id', 'type': 'integer'},\n                    {'name': 'name', 'type': 'string'}\n                ]\n            }\n        }\n    ]\n}\n\n# Simulate a file on disk (or create it for real)\ncsv_data = \"id,name\\n1,London\\n2,Paris\"\nwith open('cities.csv', 'w') as f:\n    f.write(csv_data)\n\nwith open('datapackage.json', 'w') as f:\n    json.dump(descriptor, f, indent=2)\n\n# Load the data package\npackage = Package('datapackage.json')\n\n# Validate the package\nif package.valid:\n    print(f\"Package '{package.name}' is valid!\")\nelse:\n    print(\"Package validation errors:\")\n    for error in package.errors:\n        print(f\"- {error}\")\n\n# Get a resource\ncities_resource = package.get_resource('cities')\n\n# Read data from the resource\nprint(\"\\nCities data (keyed=True):\")\nfor row in cities_resource.read(keyed=True):\n    print(row)\n\n# Clean up created files\nos.remove('cities.csv')\nos.remove('datapackage.json')","lang":"python","description":"This quickstart demonstrates how to create a `datapackage.json` and a resource file, then load, validate, and read data from a `datapackage.Package` object. It includes an example of accessing resources and iterating through their data."},"warnings":[{"fix":"Update your code to use properties like `package.resources`, `resource.descriptor`, and `resource.read()` instead of deprecated methods. Consult the v1.0.0 changelog for a full list of changes.","message":"Major API changes were introduced in version 1.0.0, which affect how package and resource metadata/data are accessed. Methods like `get_resources()`, `get_metadata()`, and `get_data()` were replaced by properties or renamed methods.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure you are using the correct library for your needs. If you only need to work with Data Packages, `datapackage-py` is sufficient. If you need advanced data processing, validation beyond simple Data Package schemas, or integration with diverse data sources, consider `frictionless` (install with `pip install frictionless`). Note that `frictionless` has its own `Package` and `Resource` objects with different APIs.","message":"Users often confuse `datapackage-py` with the broader `frictionless` framework. `datapackage-py` strictly implements the Data Package standard, while `frictionless` (v4+) is a much larger data framework that includes data package capabilities but offers a different API and more extensive features (e.g., pipelines, schemas, validation for various data sources).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your system's certificate authorities are up-to-date. For temporary workarounds, you might set `verify_ssl=False` (not recommended for production) or configure `REQUESTS_CA_BUNDLE` environment variable if using a custom CA.","message":"When loading remote resources, `datapackage` relies on `requests`. If you encounter SSL errors (e.g., `SSLCertVerificationError`), it's often an environment-specific issue rather than a library bug.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure your `datapackage.json` adheres to the Data Package specification, including a valid 'resources' array. Check for typos or structural errors in the JSON.","cause":"The `datapackage.json` descriptor is missing the mandatory 'resources' key, or it's malformed.","error":"jsonschema.exceptions.ValidationError: 'resources' is a required property"},{"fix":"Verify that the path provided to `Package()` is correct and that the `datapackage.json` file exists in that location. For relative paths, ensure your script's current working directory is as expected.","cause":"The `Package()` constructor could not find the `datapackage.json` file at the specified path.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'datapackage.json'"},{"fix":"Specify the correct encoding in the resource descriptor in `datapackage.json` (e.g., `'encoding': 'ISO-8859-1'`) or explicitly when loading data if available for the particular data source.","cause":"The resource file (e.g., CSV) is not encoded in UTF-8, but `datapackage` is attempting to read it as such by default.","error":"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte"}]}