pycarbontracer/README.md

36 lines
1.2 KiB
Markdown
Raw Normal View History

# CarbonTracer API Python Client
2023-08-16 09:28:38 +00:00
This is a Python client for CarbonTracer. It is a wrapper around the [CarbonTracer](https://carbontracer.uni-graz.at/) REST API, which allows you to calculate CO2 equivalents for personal transport.
2023-08-16 09:28:38 +00:00
## Installation
```bash
pip install git+https://kumig.it/kumitterer/pycarbontracer.git
2023-08-16 09:28:38 +00:00
```
## Usage
```python
from pycarbontracer import CarbonTracer
# Create a new CarbonTracer instance
2023-08-16 09:28:38 +00:00
ct = CarbonTracer("YOUR_API_KEY")
2023-08-16 09:28:38 +00:00
# Or use CarbonTracer.from_config() if you have a config.ini in the format of config.dist.ini
2023-08-16 09:28:38 +00:00
# Calculate the CO2 equivalents for a train trip from Graz to Vienna
2023-08-16 09:28:38 +00:00
result = ct.routing("train", "8010 Graz", "1010 Wien")
2023-08-16 09:28:38 +00:00
# Print the result
print(f"CO2 equivalents: {result["response"]["data"]["co2eq"]} {result["response"]["data"]["unitco2eq"]}")
2023-08-16 09:28:38 +00:00
```
The `CarbonTracer` class also has methods for the `location`, `address` and `co2only` endpoints, as documented in the [CarbonTracer API documentation](https://carbontracer.uni-graz.at/api-doc). The documentation also includes information about the input and output parameters, so make sure to check it out.
2023-08-16 09:28:38 +00:00
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.