Skip to main content

Python library to work with OpenEPD format

Project description

Python Library to work with OpenEPD format


This library is a Python library to work with OpenEPD format.

About OpenEPD

openEPD is an open data format for passing digital third-party verified Environmental Product Declarations (EPDs) among Program Operators, EPD Databases, Life Cycle Analysis tools, design tools, reporting, and procurement.

Unlike print or PDF EPDs, openEPD provides a shared and precise format to express and refer to EPDs in ways that modern databases can use. openEPD can be used alongside a printable document, or can generate printable EPDs.

Unlike existing formats such as ILCD+EPD, it enforces a key set of guarantees for interoperable data processing,
including uniqueness of organizations/plants, precise PCR references, and dated version control.

The openEPD format is extensible. Standard extensions exist for concrete products, and for documenting supply-chain specific data.

Read More about OpenEPD format here.

Usage

Usage

❗ ATTENTION: Pick the right version. The cornerstone of this library models package representing openEPD models. Models are defined with Pydantic library which is a dependency for openepd package. If you use Pydantic in your project carefully pick the version:

  • Use version below 2.0.0 if your project uses Pydantic version below 2.0.0
  • Use version 2.x.x or higher if your project uses Pydantic version 2.0.0 or above

Models

The library provides the Pydantic models for all the OpenEPD entities. The models are available in the openepd.models module. For mode details on the usage please refer to Pydantic documentation.

API Client

The library provides the API client to work with the OpenEPD API. The client is available in the openepd.client module. Currently, the only available implementation is based on synchronous requests library. Client provides the following features:

  • Error handling - depending on HTTP status code the client raises different exceptions allowing to handle errors in a more granular way.
  • Throttling - the client is able to throttle the requests to the API to avoid hitting the rate limits.
  • Retry - the client is able to retry the requests in case of the network errors.

API Client Usage

The following example illustrates the usage of the API client:

from openepd.api.sync_client import OpenEpdApiClientSync

# Setup the client
api_client = OpenEpdApiClientSync(
    "https://openepd.buildingtransparency.org/api",
    "<Your API Token>",
)

# Use API, e.g. get EPD by ID
epd = api_client.epds.get_by_openxpd_uuid("ec3b9j5t")

Bundle

Bundle is a format which allows to bundle multiple openEPD objects together (it might be EPDs, PCRs, Orgs + any other files which might be related to mentioned objects like pdf version of EPD, logo of the PCR company, etc).

Bundle consists of root-level and dependent objects. Dependents are objects which are referenced by root-level objects or related to the root-level objects. For example, EPD is a root-level object, PDF version of this EPD is a dependent, translated version of the same EPD is dependent as well.

The following example illustrates reading of the bundle file containing PCR and some of the related objects:

from openepd.bundle.reader import DefaultBundleReader
from openepd.bundle.model import AssetType, RelType

with DefaultBundleReader("test-bundle.epb") as reader:  # You could either file path or file-like object
    pcr = reader.get_first_root_asset(AssetType.Pcr)  # Get FIRST available root level PCR object. We consider that
    # there is only one PCR in the bundle
    # Read relative PDF file of the found PCR. `related_pdf` is a reference to the PDF file containing metadata only
    related_pdf = reader.get_first_relative_asset(pcr, RelType.Pdf)
    # We have to read the file content separately
    with reader.read_blob_asset(related_pdf) as f:
        pass  # Do something with the file content here

The next example illustrates the writing of the bundle file:

from openepd.bundle.writer import DefaultBundleWriter
from openepd.bundle.model import RelType
from openepd.model.pcr import Pcr

pcr_obj = Pcr(...)  # Let's assume we already have PCR object

with DefaultBundleWriter("my-bundle.epb") as writer, open("test-pcr.pdf", "rb") as pcr_pdf_file:
    # Add our PCR to the bundle. We do not specify any extra information, however you might what to add language
    # and a file name to make it look nicer in the bundle. If omitted the name will be generated automatically.
    pcr_asset = writer.write_object_asset(pcr_obj)
    # Now add related PDF document. We have to specify the content type, related (parent) object and the 
    # type of relation. Again, optionally you might want to specify the language and file name.
    writer.write_blob_asset(pcr_pdf_file, "application/pdf", pcr_asset, RelType.Pdf)

Credits

This library has been written and maintained by C-Change Labs.

License

This library is licensed under Apache 2. This means you are free to use it in commercial projects.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openepd-1.4.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

openepd-1.4.0-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

Details for the file openepd-1.4.0.tar.gz.

File metadata

  • Download URL: openepd-1.4.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.8 Linux/6.2.0-1019-azure

File hashes

Hashes for openepd-1.4.0.tar.gz
Algorithm Hash digest
SHA256 d32dfbc7420e9425826731f8176a0d3685e1c2f5433d7e0d92005a4a51f854dc
MD5 2179b26a4ebaf13e799194a3348e6466
BLAKE2b-256 2f3f46b743e2561266bd80507b4144479b3e8bc6e6842f26255a767e06513adf

See more details on using hashes here.

File details

Details for the file openepd-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: openepd-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 68.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.8 Linux/6.2.0-1019-azure

File hashes

Hashes for openepd-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cddd317d234150a0a9c14fb06ced29484b2111e08f844623c8db3421464199c2
MD5 580a2ac247389ca27d3eaf3e4ad5d4e0
BLAKE2b-256 13bffc5d15cb437b5a7206fca2f97edbf97474418aada25dc56936ee3e10a3a1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page