FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add sample for low cost instances by zoercai · Pull Request #392 · googleapis/python-spanner · GitHub

This repository was archived by the owner on Jun 8, 2026. It is now read-only.
/ python-spanner Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 28 additions & 0 deletions samples/samples/snippets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ def create_instance(instance_id):
# [END spanner_create_instance]


# [START spanner_create_instance_with_processing_units]
def create_instance_with_processing_units(instance_id, processing_units):
"""Creates an instance."""
spanner_client = spanner.Client()

config_name = "{}/instanceConfigs/regional-us-central1".format(
spanner_client.project_name
)

instance = spanner_client.instance(
instance_id,
configuration_name=config_name,
display_name="This is a display name.",
processing_units=processing_units,
)

operation = instance.create()

print("Waiting for operation to complete...")
operation.result(120)

print("Created instance {} with {} processing units".format(
instance_id, instance.processing_units))


# [END spanner_create_instance_with_processing_units]


# [START spanner_create_database]
def create_database(instance_id, database_id):
"""Creates a database and tables for sample data."""
Expand Down
9 changes: 9 additions & 0 deletions samples/samples/snippets_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def cleanup_old_instances(spanner_client):


INSTANCE_ID = unique_instance_id()
LCI_INSTANCE_ID = unique_instance_id()
DATABASE_ID = unique_database_id()
CMEK_DATABASE_ID = unique_database_id()

Expand Down Expand Up @@ -81,6 +82,14 @@ def test_create_instance(spanner_instance):
spanner_instance.reload()


def test_create_instance_with_processing_units(capsys):
processing_units = 500
snippets.create_instance_with_processing_units(LCI_INSTANCE_ID, processing_units)
out, _ = capsys.readouterr()
assert LCI_INSTANCE_ID in out
assert "{} processing units".format(processing_units) in out


def test_create_database(database):
# Reload will only succeed if the database exists.
database.reload()
Expand Down

Back | FazBrowse Home | New Git URL