{"id":42482612,"url":"https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo","last_synced_at":"2026-01-28T11:15:43.284Z","repository":{"id":40430422,"uuid":"461955602","full_name":"cloudspannerecosystem/spanner-sqlalchemy-demo","owner":"cloudspannerecosystem","description":"A demo application for Cloud Spanner SQLAlchemy ORM, simple ranking API for gaming use cases.","archived":false,"fork":false,"pushed_at":"2024-04-30T07:45:57.000Z","size":307,"stargazers_count":7,"open_issues_count":14,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-30T08:50:46.475Z","etag":null,"topics":["alembic","cloud-spanner","fastapi","gcp-cloud-run","poetry","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudspannerecosystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-21T17:02:13.000Z","updated_at":"2023-11-20T20:56:48.000Z","dependencies_parsed_at":"2024-05-17T05:00:38.443Z","dependency_job_id":null,"html_url":"https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/cloudspannerecosystem/spanner-sqlalchemy-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-sqlalchemy-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-sqlalchemy-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-sqlalchemy-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-sqlalchemy-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudspannerecosystem","download_url":"https://codeload.github.com/cloudspannerecosystem/spanner-sqlalchemy-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudspannerecosystem%2Fspanner-sqlalchemy-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28844861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T10:53:21.605Z","status":"ssl_error","status_checked_at":"2026-01-28T10:53:20.789Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alembic","cloud-spanner","fastapi","gcp-cloud-run","poetry","sqlalchemy"],"created_at":"2026-01-28T11:15:42.460Z","updated_at":"2026-01-28T11:15:43.278Z","avatar_url":"https://github.com/cloudspannerecosystem.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloud Spanner + SQLAlchemy demo \n[![pytest \u0026 flake8](https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo/actions/workflows/pytest_flake8.yaml/badge.svg)](https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo/actions/workflows/pytest_flake8.yaml)\n[![docker_build](https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo/actions/workflows/docker_build.yaml/badge.svg)](https://github.com/cloudspannerecosystem/spanner-sqlalchemy-demo/actions/workflows/docker_build.yaml)  \n\nThis is a demo application for [Cloud Spanner SQLAlchemy ORM](https://github.com/googleapis/python-spanner-sqlalchemy).  \nA simple ranking API for gaming use cases.\n\n## Building blocks\n* Language: [Python 3](https://docs.python.org/3/)\n* Python package and virtualenv tool: [Poetry](https://github.com/python-poetry/poetry)\n* Framework: [FastAPI](https://fastapi.tiangolo.com/)\n* ORM: [SQLAlchemy](https://www.sqlalchemy.org/)\n* Migration tool: [Alembic](https://alembic.sqlalchemy.org/en/latest/)\n* Server: [Cloud Run](https://cloud.google.com/run/)\n* DB: [Cloud Spanner](https://cloud.google.com/spanner/)\n* Container registry: [Artifact Registry](https://cloud.google.com/artifact-registry/)\n* CI/CD: [GitHub Actions](https://github.co.jp/features/actions) \n\n# For who want to play with this code\n## 1. install dependencies to your local machine\n```shell\ngit clone https://github.com/kazshinohara/spanner-sqlalchemy-demo\ncd spanner-sqlalchemy-demo\npoetry install\n```\n\n## 2. Setup Cloud Spanner and DB Migration\nSet environment variables which are needed for the following steps.\n```shell\nexport PROJECT_ID=\"\"\nexport INSTANCE_ID=\"\"\nexport DATABASE_ID=\"\"\nexport SA_NAME=\"\"\nexport SA_KEY_NAME=\"\"\n```\n\nCreate a service account for this demo.\n```shell\ngcloud iam service-accounts create ${SA_NAME}\n```\n\nAssign role to the service account. \n```shell\ngcloud projects add-iam-policy-binding ${PROJECT_ID} --member \"serviceAccount:${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\" --role \"roles/spanner.databaseAdmin\"\n```\n\nDownload the key file to your local machine.\n```shell\ngcloud iam service-accounts keys create ${SA_KEY_NAME} \\\n--iam-account=${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\n```\n\nSet your key file location as an environment variable.\n```shell\nexport GOOGLE_APPLICATION_CREDENTIALS=\"\"\n```\n\nCreate Cloud Spanner instance and database.\n```shell\ngcloud spanner instances create ${INSTANCE_ID} --config=regional-asia-northeast1 --description=\"demo\" --nodes=1\ngcloud spanner databases create ${DATABASE_ID} --instance=${INSTANCE_ID}\n```\n\nDB migration, Alembic uses your service account's credential to access Cloud Spanner.\n```shell\ncd spanner-sqlalchemy-demo/app\npoetry run alembic revision --autogenerate -m \"Initial migration\"\npoetry run alembic upgrade head\n```\n\n## 3. Start API server at your local machine\n*Note: The following steps need environment variables which are set at Section 2.*\n\n```shell\ncd spanner-sqlalchemy-demo\npoetry run uvicorn app.main:app --reload\nopen http://127.0.0.1:8000/\n```\n\n## 4. Run unit test at your local machine\n*Note: The following steps need environment variables which are set at Section 2.*\n\nRun Cloud Spanner emulator.\n```shell\ndocker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator\n```\n\nSet up Cloud Spanner emulator.\n```shell\ncd spanner-sqlalchemy-demo/tests\nchmod u+x spanner_emulator_setup.sh\n./spanner_emulator_setup.sh\n```\n\nSet environment variables which are needed for the following steps.\n```shell\nexport SPANNER_EMULATOR_HOST=localhost:9010\nexport K_SERVICE=spanner-sqlalchemy-demo\nexport K_REVISION=spanner-sqlalchemy-demo-00001-thx\n```\n\nRun the unit test.\n```shell\ncd spanner-sqlalchemy-demo/tests\npoetry run pytest\n```\n\n## 5. Create the container image and deploy to Cloud Run\n*Note: The following steps need environment variables which are set at Section 2.*\n\nSet an environment variable which are needed for the following steps.  \nPlease make sure that you have a docker image repo at Artifact Registry.\n```shell\nexport REPOSITORY_NAME=\"\"\n```\n\nBuild a container image.\n```shell\ncd spanner-sqlalchemy-demo \ndocker build -t asia-northeast1-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/spanner-sqlalchemy-demo:1.0.0 .\n```\n\nPush the image to Artifact Registry\n```shell\ncd spanner-sqlalchemy-demo \ndocker push asia-northeast1-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/spanner-sqlalchemy-demo:1.0.0\n```\n\nDeploy the container image to Cloud Run.\n```shell\ngcloud run deploy spanner-sqlalchemy-demo \\\n--image asia-northeast1-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/spanner-sqlalchemy-demo:1.0.0 \\\n--allow-unauthenticated \\\n--set-env-vars=PROJECT_ID=${PROJECT_ID},INSTANCE_ID=${INSTANCE_ID},DATABASE_ID=${DATABASE_ID} \\\n--service-account=${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com \\\n--region=asia-northeast1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudspannerecosystem%2Fspanner-sqlalchemy-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudspannerecosystem%2Fspanner-sqlalchemy-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudspannerecosystem%2Fspanner-sqlalchemy-demo/lists"}