cloudfit-provider-gcp
GCP Compute Engine provider plugin for cloudfit-core.
Fetches machine types, pricing, and availability from the GCP Compute Engine API and normalizes them into MachineType objects that cloudfit-core understands.
Installation
pip install cloudfit-provider-gcp
Requires Python 3.10+ and cloudfit-core>=0.6.1.
Authentication
Uses Application Default Credentials. Set up once with:
gcloud auth application-default login
Or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to a service account key path. In production (Cloud Run, GKE), credentials are picked up automatically from the instance metadata server: no configuration needed.
Quick start
from cloudfit_provider_gcp import GCPProvider
from cloudfit import rank, WorkloadProfile
# initialize: no credentials needed if ADC is configured
provider = GCPProvider(project_id="your-gcp-project")
# fetch all machine types for a region
instances = provider.fetch_instances(region="us-central1")
print(f"fetched {len(instances)} machine types")
# plug directly into cloudfit-core
profile = WorkloadProfile(
vcpu=60,
ram_gb=224,
workload="io-intensive",
archetype="io",
optimize_for="balanced",
)
results = rank(profile, instances)
for r in results[:3]:
print(f"{r.instance.id:35s} score={r.score:.2f} ${r.instance.price_hr:.2f}/hr")
Fetching multiple regions
from cloudfit_provider_gcp import GCPProvider
provider = GCPProvider(project_id="your-gcp-project")
regions = ["us-central1", "us-east1", "europe-west1", "asia-east1"]
all_instances = []
for region in regions:
all_instances.extend(provider.fetch_instances(region=region))
print(f"total: {len(all_instances)} machine types across {len(regions)} regions")
Examples
Runnable scripts are in examples/:
| Script | Needs GCP credentials? | What it shows |
|---|---|---|
recommend.py |
yes (ADC) | live GCPProvider.fetch_instances() → cloudfit.rank() |
recommend_offline.py |
no | recorded fixture → normalize_machine_type() → cloudfit.rank() |
Try the offline one first: it runs anywhere, no GCP account required:
python examples/recommend_offline.py
Ranking for 32 vCPU / 120 GB (optimize_for=balanced):
ok n2-standard-32 score=1.00 $ 1.53/hr [active]
ok c2-standard-60 score=0.61 $ 2.82/hr [active]
ok c3d-standard-60-lssd score=0.60 $ 2.87/hr [active]
-- a2-highgpu-1g $ 0.73/hr [active] ✗ RAM 85 GB < required 120 GB
-- n1-standard-8 $ 0.37/hr [deprecated] ✗ RAM 30 GB < required 120 GB
-- f1-micro $ 0.03/hr [tombstoned] ✗ RAM 1 GB < required 120 GB
Pricing
Pricing is fetched from the GCP Cloud Billing Catalog API. Prices are on-demand (no committed-use or spot discount), reconstructed per instance from each family's vCPU and RAM SKU rates. If a family's SKUs can't be matched, price_hr falls back to 0.0 and the instance is still scored (its cost_score is just 0).
price_hr = provider.get_pricing("n2-standard-32", region="us-central1")
# → 1.5468
Cron / scheduled refresh
For production use, run the fetcher on a daily schedule and write results to the cloudfit registry store (PostgreSQL). The recommended pattern is a Cloud Scheduler trigger invoking a Cloud Run Job.
from cloudfit_provider_gcp import GCPProvider
from cloudfit_provider_gcp.registry import write_to_registry
provider = GCPProvider(project_id="your-gcp-project")
instances = provider.fetch_instances_all_regions()
write_to_registry(instances, database_url=os.environ["DATABASE_URL"])
Deprecation handling
When GCP marks a machine type as deprecated, the provider sets status="deprecated" on the MachineType. When a type is fully removed, it becomes status="tombstoned": it is never deleted from the registry, so existing configs can warn instead of silently breaking.
Repository structure
cloudfit-provider-gcp/
├── README.md
├── CONTRIBUTING.md
├── CITATION.cff
├── pyproject.toml
├── LICENSE
├── .gitignore
│
├── cloudfit_provider_gcp/
│ ├── __init__.py # exports GCPProvider
│ ├── provider.py # GCPProvider: implements Provider base class
│ ├── normalizer.py # raw GCP API response → MachineType
│ ├── pricing.py # Cloud Billing Catalog API → price_hr
│ ├── regions.py # GCP region list + helpers
│ └── registry.py # write normalized instances to PostgreSQL
│
├── examples/
│ ├── recommend.py # live fetch → rank (needs GCP credentials)
│ └── recommend_offline.py # fixture → rank (no credentials needed)
│
└── tests/
├── test_normalizer.py # unit tests: no API calls needed
├── test_regions.py
└── fixtures/
└── machine_type_response.json # recorded GCP API response
Related projects
cloudfit-core: scoring enginecloudfit-provider-aws: AWS provider (planning phase)cloudfit-api: REST API over the scoring engine (live demo)cloudfit-ui: Gradio UI over the scoring engine (live demo)samplesheet-parser: Illumina SampleSheet parser
License
Apache 2.0: see LICENSE.
Author: Chaitanya Krishna Kasaraneni · Google Scholar · ORCID 0000-0001-5792-1095
Metadata
Release files for cloudfit-provider-gcp 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cloudfit_provider_gcp-0.2.0.tar.gz | 27.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cloudfit_provider_gcp-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.4 kB
Release files / cloudfit_provider_gcp-0.2.0.tar.gz
| Download URL | cloudfit_provider_gcp-0.2.0.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d357e1f197a066ac51769bd86d52ef2c846c99c49317452f022052148c723b0
|
|
BLAKE2b-256 checksum How to use checksums |
79eb5f3003635d801e6f4f6726d9ef5950818bb9124d273310f2c11ca68da86a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logRelease files / cloudfit_provider_gcp-0.2.0-py3-none-any.whl
| Download URL | cloudfit_provider_gcp-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
565a5f3e560c129f4a8009ff68202fb7eb92c7a4a5a78bb424737bdf0698672c
|
|
BLAKE2b-256 checksum How to use checksums |
1f10a393e4b1a79344c41133033f4b77e42b420cb5f7a63a7e923d9d060c3a6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency log