Package: carbon-calculator
Carbon CalculatorThe Carbon Calculator tool aims to calculate the CO2 emissions of any website. The tool is the porting in python of the WholeGrain AgencyCarbon Calculator tool, but it is faster and with more metrics.How it worksThe tool uses the samealgorithmof the original tool but it is faster because it doesn't call external APIs.
Soon more infos in a Medium post.RequirementsPython >=3.6The Green Web Foundation DatasetLightHouse ToolInstallationInstall the Green Web Foundation DatasetGo to theGreen Web Foundation, get the most updated link and substitute it in the following command:mkdir data && cd data
curl https://tgwf-green-domains-live.s3.nl-ams.scw.cloud/green_urls_2021-12-08.db.gz | gunzip -c > green_urls.dbInstall the Lighthouse toolnpm install -g lighthouseInstall the Carbon Calculator toolpipinstallcarbon-calculatorUsing the toolAs Python Libraryfromcarbon.calculatorimportCarbonCalculatorfromcarbon.servicesimportLighthouseService,GreenWebService# If lighthouse tool is installed globally the following row can be omittedlighthouse=LighthouseService(lighthouse=PATH_OF_LIGHTHOUSE_TOOL)# It loads the Green Web Dataset DB (must be a SQL3Lite file)greenweb=GreenWebService(greenweb=PATH_URL_OF_GREEN_DB)# It calculates CO2 emissionscarbon=CarbonCalculator(lighthouse=lighthouse,greenweb=greenweb)carbon.footprint("https://www.unime.it")print(carbon.co2_grams)//0.29566587414592505As Python Library from INI FileExample ofconfig.inifile:[GREENWEB]
GREENWEB_PATH = /Users/giovanni/projects/carbon-calculator/data/green_urls.db

[LIGHTHOUSE]
LIGHTHOUSE_PATH = /Users/giovanni/.nvm/versions/node/v14.17.6/bin/lighthouseIf Lighthouse tool is installed globally set the LIGHTHOUSE_PATH emptyfromcarbon.calculatorimportCarbonCalculatorcarbon=CarbonCalculator.from_ini_file('config.ini')carbon.footprint("https://www.unime.it")print(carbon.co2_grams)//0.29566587414592505As Command Line Interface (CLI)carbon-cli -h

usage: carbon-cli [-h] -db GREENWEB [-lh LIGHTHOUSE] website

Carbon Calculator - the tool calculates the carbon emissions (CO2) and green infos of any website

positional arguments:
  website               The URL to analyze

optional arguments:
  -h, --help            show this help message and exit
  -db GREENWEB, --greenweb GREENWEB
                        (Mandatory) - The path of the Green Web Foundation DB (SQL3Lite DB file)
  -lh LIGHTHOUSE, --lighthouse LIGHTHOUSE
                        (Optional) - The path of the Lighthouse toolcarbon-cli --greenweb=/Users/giovanni/projects/carbon-calculator/data/green_urls_2021-12-01.db  --lighthouse=/Users/giovanni/.nvm/versions/node/v14.17.6/bin/lighthouse https://www.unime.itOutput{
    "date": "2021-12-10T16:07:20.881173+01:00",
    "url": "https://www.unime.it",
    "hosting_green": false,
    "co2_grams": 2.3048954692203547,
    "energy_kWh": 0.004852411514148116,
    "water_litres": 1.2819828599803613,
    "resources": {
        "transfer_size_bytes": {
            "total": 3823256,
            "total_weighted": 2886558,
            "html": 18332,
            "css": 220144,
            "javascript": 573821,
            "image": 2962769,
            "font": 1613,
            "audio": 0,
            "video": 0,
            "other": 46577
        },
        "resources_size_bytes": {
            "total": 8375362,
            "html": 278333,
            "css": 3448588,
            "javascript": 1645906,
            "image": 2955453,
            "font": 1268,
            "audio": 0,
            "video": 0,
            "other": 45814
        }
    }
}Fields availableNameFormatDetailExampleco2_gramsfloatThe CO2 Emissions in grams2.3048954692203547dateYYYY-MM-DDThh:mm:ss.sTZD (ISO8601)Date and time of the measurement2021-12-10T16:07:20.881173+01:00energy_kWhfloatThe power energy consumed in kWh (kiloWatt-hour)0.004852411514148116hosting_greenbooleanboolean - true if the hosting is present in the Green Web Foundation DB otherwise falseTrueresourcesarrayInfo Resources (See table below)urlstringThe website to analyzehttps://www.unime.itwater_litresfloatThe amount of water to boil to emit the same amount of CO2 in the air1.2819828599803613Info ResourcesArray key namesFormatDetailExampletransfer_size_bytes[total]intThe data traffic total in bytes  (compressed)3823256transfer_size_bytes[total_weighted]intThe weighted data traffic total in bytes (considering caches)2886558transfer_size_bytes[html]intThe HTML data traffic total in bytes18332transfer_size_bytes[css]intThe CSS data traffic total in bytes220144transfer_size_bytes[javascript]intThe JAVASCRIPT data traffic total in bytes573821transfer_size_bytes[image]intThe IMAGE data traffic total in bytes2962769transfer_size_bytes[font]intThe FONT data traffic total in bytes1613transfer_size_bytes[audio]intThe AUDIO data traffic total in bytes0transfer_size_bytes[video]intThe VIDEO data traffic total in bytes0transfer_size_bytes[other]intThe OTHER data traffic total in bytes46577resources_size_bytes[total]intThe Web resources total size in bytes8375362resources_size_bytes[html]intThe HTML resource size in bytes278333resources_size_bytes[css]intThe CSS resources size in bytes3448588resources_size_bytes[javascript]intThe JAVASCRIPT resources size in bytes1645906resources_size_bytes[image]intThe IMAGE resources size in bytes2955453resources_size_bytes[font]intThe FONT resources size in bytes1268resources_size_bytes[audio]intThe AUDIO resources size in bytes0resources_size_bytes[video]intThe VIDEO resources size in bytes0resources_size_bytes[other]intThe OTHER resources size in bytes45814ResourcesLighthouse:github repoGreen Web Dataset:websiteLicenseCarbon Calculator:MIT licenseGreen Web Dataset:Open Database LicenseCreditsGiovanni Pirrotta