No description
Kumi
22a13889d2
This commit adds return type annotations to the `address`, `routing`, and `co2only` methods in the `CarbonTracer` class. This helps improve code readability and provides better documentation by specifying the expected return types for these methods. |
||
---|---|---|
src/pycarbontracer | ||
.gitignore | ||
.gitlab-ci.yml | ||
config.dist.ini | ||
LICENSE | ||
pyproject.toml | ||
README.md | ||
test.py |
CarbonTracer API Python Client
This is a Python client for CarbonTracer. It is a wrapper around the CarbonTracer REST API, which allows you to calculate CO2 equivalents for personal transport.
Installation
pip install pycarbontracer
Usage
from pycarbontracer import CarbonTracer
# Create a new CarbonTracer instance
ct = CarbonTracer("YOUR_API_KEY")
# Or use CarbonTracer.from_config() if you have a config.ini in the format of config.dist.ini
# Calculate the CO2 equivalents for a train trip from Graz to Vienna
result = ct.routing("train", "8010 Graz", "1010 Wien")
# Print the result
print(f"CO2 equivalents: {result["response"]["data"]["co2eq"]} {result["response"]["data"]["unitco2eq"]}")
The CarbonTracer
class also has methods for the location
, address
and co2only
endpoints, as documented in the CarbonTracer API documentation. The documentation also includes information about the input and output parameters, so make sure to check it out.
License
This project is licensed under the MIT License - see the LICENSE file for details.