Skip to main content

Fetches data from Google Search Console and stores it into SQLite

Project description

gsc-api-handler

gsc-api-handler is a lightweight Python package designed to authorize and fetch data from the Google Search Console API, storing it directly into a local SQLite database.

🚀 Features

  • 🔐 OAuth 2.0 user authorization with automatic token refresh
  • 📊 Data fetching with pagination support
  • 🗃️ Stores GSC metrics (clicks, impressions, CTR, position) into SQLite
  • 🧩 Easily integrable with Django or other Python-based projects
  • ✅ Minimal dependencies and clean, modular structure

📦 Installation

Install the package in editable mode during development:

git clone https://github.com/your-username/gsc-api-handler.git
cd gsc-api-handler
pip install gsc-api-handler

You may want to use a virtual environment:

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install gsc-api-handler

⚙️ Configuration

This package uses python-decouple to manage environment variables.

  1. Create a .env file in the project root, outside the src/ folder.
  2. Add the following variables:
GSC_CLIENT_SECRET=gsc_credentials/client_secret.json
GSC_TOKEN_PATH=gsc_credentials/token.pickle
  1. Create a gsc_credentials/ folder and place your client_secret.json file inside.

The token will be created automatically after successful authentication.

If .env is missing, default values client_secret.json and token.pickle will be used from the current working directory.


✅ Usage Example

Here is an example script (test_fetch.py) that uses the package to fetch GSC data and store it in SQLite:

from gsc_api_handler import fetch_and_store_gsc_data

rows = fetch_and_store_gsc_data(
    site_url='sc-domain:yourdomain.com',
    db_path='gsc_yourdomain.sqlite',
    creds_path=None,  
    token_path=None, 
    dimensions=['query', 'page', 'date'], 
    start_date='2024-06-01',
    end_date='2024-06-15'
)

print(f"{rows} rows fetched and saved.")

📁 Output Table Format

The gsc_data table contains:

Column Type Description
country TEXT User country
device TEXT Device used
query TEXT Search query
page TEXT Landing page
date TEXT Date of the visit
clicks INTEGER Number of clicks
impressions INTEGER Number of impressions
ctr REAL Click-through rate
position REAL Average position in search

Table name and dimensions are fully configurable.


📚 Requirements

This package depends on:

  • google-api-python-client
  • google-auth
  • google-auth-oauthlib
  • python-dateutil
  • python-decouple

All dependencies are listed in pyproject.toml.


📤 Publishing (optional)

If you plan to publish this package on PyPI:

  1. Update pyproject.toml with your author name, email, and version.
  2. Run:
python -m build
twine upload dist/*

📝 License

This project is licensed under the MIT License


✨ Author

Developed by Miki Zivkovic
© 2025-present

Project details


Download files

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

Source Distribution

gsc_api_handler-0.0.1.tar.gz (19.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gsc_api_handler-0.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file gsc_api_handler-0.0.1.tar.gz.

File metadata

  • Download URL: gsc_api_handler-0.0.1.tar.gz
  • Upload date:
  • Size: 19.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for gsc_api_handler-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c28b7c589680ce33eec3699f59ce233fa2e5aa7add62b1f978e12ed39972a389
MD5 b4ce7ba999bdea01d0606bffd56d4174
BLAKE2b-256 a6447873adab1f802bfef44edded54a1fabe1cb16b8eb3260b2bed034d2831a9

See more details on using hashes here.

File details

Details for the file gsc_api_handler-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gsc_api_handler-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3de605123907bb5838709a0056c8942f1432860e92971aeb970116f44e331857
MD5 db50344a92858189d1c2f3ce4ecdc0d5
BLAKE2b-256 fabedbb285be299fa181288de09420f9755b67640e98757f0b9b3c7648b857f6

See more details on using hashes here.

Supported by

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