Skip to content

google/garf

garf - Python library for interacting with reporting APIs

License codecov tests

garf is a Python library for building various connectors to reporting API that provides users with a SQL-like interface to specify what needs to be extracted from the API.

Write a query and garf will do the rest- build the correct request to an API, parse response and writes it virtually anywhere.

Key features

  • Rich SQL-like syntax to interact with reporting APIs.
  • Built-in support for writing data into various local / remote storage.
  • Built-in support for post-processing saved data in BigQuery & SQL databases.
  • Easily extendable to support various APIs.
  • Available as library, CLI, FastAPI endpoint.

Supported APIs

Installation

pip install garf-executors

Usage

Use garf CLI tool to fetch data from an API

echo 'SELECT id, name AS model, data.color AS color FROM objects' > query.sql
garf  query.sql --source rest --source.endpoint=https://api.restful-api.dev

Get data from API to use in your code

from garf_core.report_fetcher import ApiReportFetcher
from garf_core.api_clients import RestApiClient
from garf_io import writer

api_client = RestApiClient(endpoint='https://api.restful-api.dev')
fetcher = ApiReportFetcher(api_client)
query = 'SELECT id, name AS model, data.color AS color FROM objects'
report = fetcher.fetch(query)

# Convert to Pandas
report.to_pandas()

# Write to CSV
writer.create_writer('csv').write(report, 'api_data')

Documentation

Explore full documentation on using and extending garf

Disclaimer

This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.