### Getting a Value from KV Store in Go Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Illustrates how to retrieve a value from the initialized Key-Value store using the `get` method. Notes that a `KeyNotFoundError` is returned if the key does not exist. ```Go store.get("k1") ``` -------------------------------- ### Initializing Google Sheets KV Store in Python Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Shows how to initialize the `GoogleSheetKVStore` for Key-Value operations using Google Sheets. Provides examples for authenticating with either a Service Account or OAuth2 flow. ```Python from pyfreedb.providers.google.auth import ServiceAccountGoogleAuthClient, OAuth2GoogleAuthClient from pyfreedb.kv import GoogleSheetKVStore, AUTH_SCOPES # If using Google Service Account. auth_client = ServiceAccountGoogleAuthClient.from_service_account_file( "", scopes=AUTH_SCOPES, ) # If using Google OAuth2 Flow. auth_client = OAuth2GoogleAuthClient.from_authorized_user_file( "", client_secret_filename="", scopes=AUTH_SCOPES, ) store = GoogleSheetKVStore( auth_client, spreadsheet_id="", sheet_name="", mode=GoogleSheetKVStore.APPEND_ONLY_MODE, ) ``` -------------------------------- ### Defining Python Dependencies Source: https://github.com/freeleh/pyfreedb/blob/main/requirements.txt Specifies the exact versions or version ranges for the Python packages required to run and develop the project. This list is typically used with pip to install dependencies. ```Python google-api-python-client==2.51.0 google-auth-httplib2==0.1.0 google-auth-oauthlib==0.5.2 requests>=2.30, <3 black>=24.10.0 mypy==0.961 isort==5.10.1 pytest==7.1.2 autoflake==2.3.1 types-requests==2.28.6 coverage==6.4.4 ``` -------------------------------- ### Count Rows in GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Illustrates how to count rows in the Google Sheet using the `count()` method. Examples include counting all rows and counting rows that match specific conditions using a `where()` clause. ```python # Count all rows. count = store.count().execute() # Count rows with conditions. count = store.count().where("name = ? OR age >= ?", "freedb", 10).execute() ``` -------------------------------- ### Query Rows in GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Shows various ways to query rows from the Google Sheet using the `select()` method. Examples include selecting all rows/columns, selecting specific columns, filtering with `where()` clauses, sorting with `order_by()`, and limiting results with `offset()` and `limit()`. ```python # Select all columns of all rows. rows = store.select().execute() # Select a few columns for all rows (non-selected struct fields will have default value). rows = store.select("name").execute() # Select rows with conditions. rows = store.select().where("name = ? OR age >= ?", "freedb", 10).execute() # Select rows with sorting/order by. from pyfreedb.row import Ordering rows = store.select().order_by(Ordering.ASC("name"), Ordering.DESC("age")).execute() # Select rows with offset and limit rows = store.select().offset(10).limit(20).execute() ``` -------------------------------- ### Initializing Google Sheets KV Store with Different Modes in Go Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Explains and demonstrates the two supported modes for the `GoogleSheetKVStore`: `DEFAULT_MODE` and `APPEND_ONLY_MODE`. Shows how to specify the mode during store initialization. ```Go // Default mode store = GoogleSheetKVStore( auth_client, spreadsheet_id="", sheet_name="", mode=GoogleSheetKVStore.DEFAULT_MODE, ) // Append only mode store = GoogleSheetKVStore( auth_client, spreadsheet_id="", sheet_name="", mode=GoogleSheetKVStore.APPEND_ONLY_MODE, ) ``` -------------------------------- ### Initialize GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Demonstrates how to initialize the `GoogleSheetRowStore` using either a Google Service Account or OAuth2 credentials. Requires providing the authentication client, spreadsheet ID, sheet name, and the object class representing the row structure. ```python from pyfreedb.providers.google.auth import ServiceAccountGoogleAuthClient, OAuth2GoogleAuthClient from pyfreedb.row import GoogleSheetRowStore, AUTH_SCOPES # If using Google Service Account. auth_client = ServiceAccountGoogleAuthClient.from_service_account_file( "", scopes=AUTH_SCOPES, ) # If using Google OAuth2 Flow. auth_client = OAuth2GoogleAuthClient.from_authorized_user_file( "", client_secret_filename="", scopes=AUTH_SCOPES, ) store = GoogleSheetRowStore( auth_client, spreadsheet_id="", sheet_name="", object_cls=Person, ) ``` -------------------------------- ### Setting a Key-Value Pair in KV Store in Go Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Demonstrates how to store a key-value pair in the Key-Value store using the `set` method. The value is provided as a byte slice. ```Go store.set("k1", b"some_value") ``` -------------------------------- ### Mapping Model Fields to Google Sheet Columns in Python Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Demonstrates how to define pyfreedb models and control the mapping between model fields and Google Sheet column names. Shows the default behavior (using field name) and explicit mapping using the `column_name` argument. ```Python # This will map to the exact column name of "name" and "age". class Person(models.Model): name = models.StringField() age = models.IntegerField() # This will map to the exact column name of "Name" and "Age". class Person(models.Model): name = models.StringField(column_name="Name") age = models.IntegerField(column_name="Age") ``` -------------------------------- ### Deleting a Key from KV Store in Go Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Shows how to remove a key and its associated value from the Key-Value store using the `delete` method. ```Go store.delete("k1") ``` -------------------------------- ### Insert Rows into GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Demonstrates how to insert new rows into the Google Sheet. Takes a list of objects (instances of the defined model class) and uses the `insert()` method to add them to the sheet. ```python rows = [Person(name="no_pointer", age=10), Person(name="with_pointer", age=20)] store.insert(rows).execute() ``` -------------------------------- ### Update Rows in GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Shows how to update existing rows in the Google Sheet using the `update()` method. Updates can be applied to all rows or filtered using a `where()` clause. The update data is provided as a dictionary mapping field names to new values. ```python # Update all rows. store.update({"name": "new_name", "age": 100}).execute() # Update rows with conditions. store.update({"name": "new_name", "age": 100}).where("name = ? OR age >= ?", "freedb", 10).execute() ``` -------------------------------- ### Define Row Store Model Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Defines a Python class representing a row in the Google Sheet, inheriting from `pyfreedb.row.models.Model`. Fields are defined using specific field types like `StringField` and `IntegerField`. ```python from pyfreedb.row import models class Person(models.Model): name = models.StringField() age = models.IntegerField() ``` -------------------------------- ### Delete Rows from GoogleSheetRowStore Source: https://github.com/freeleh/pyfreedb/blob/main/README.md Explains how to delete rows from the Google Sheet using the `delete()` method. Rows can be deleted based on conditions specified by a `where()` clause, or all rows can be deleted if no condition is provided. ```python # Delete all rows. store.delete().execute() # Delete rows with conditions. store.delete().where("name = ? OR age >= ?", "freedb", 10).execute() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.