Skip to main content

CGC SDK examples

This section contains complete Python examples for the installed cgcsdk package.

Setup​

Create and activate a virtual environment:

python -m venv venv
# PowerShell
venv\Scripts\Activate.ps1

# Linux/macOS
source venv/bin/activate

Install the SDK:

pip install cgcsdk

Confirm that the required CGC context is selected:

cgc context list

SDK examples​

The SDK examples page contains these existing examples:

ExamplePurpose
basic_compute.pyCreate, monitor, expose, and remove a compute resource.
job_workflow.pyCreate and monitor jobs with the Jobs API.
port_management.pyConfigure internal and external resource ports.
database_connection.pyDeploy and connect to a PostgreSQL resource.

Each complete script is displayed on the page and can be created in your own project.

Workflow examples​

The Workflow examples page demonstrates the newer Workflow API:

  • file-processing jobs,
  • PyTorch image processing with a volume and Filebrowser,
  • processing multiple images with for_each(),
  • HTTP inference,
  • Roboflow dataset download,
  • pretrained YOLO and RT-DETR inference.

These examples are separate from the existing Jobs, Resource, Port, and Database examples. They use App and the higher-level workflow classes from cgc.sdk.

Troubleshooting​

If imports fail, verify the active environment and installed package:

python -c "import cgc.sdk; print('CGC SDK imported successfully')"

For authentication or context problems, run:

cgc context list