Skip to main content

A no-frills Python library for interacting with the Google AppSheet API.

Project description

py-appsheet

A no-frills Python library for interacting with Google AppSheet

Background and Setup

  • To work with this you need to create an AppSheet App first (i.e. not just an AppSheet Database).
  • To enable working with the API, you must go into the app's settings (gear icon) and then the integrations sub-item on the left. There you will find the App ID (make sure it's switched to enabled) and can create an Application Access key.
  • Be sure to not write these explicitly into your code. Instead it's better to store these in a .env file (make sure .gitignore lists the .env if working with a repo) and use os.environ.get() to pull in the secret values to work with them.
  • Some basic troubleshooting tips:
    • Make sure that you have your key column set correctly and that your schema is up-to-date (can be regenerated in the data view for the application)
    • Leverage Appsheet's Log Analyzer to get in-depth error messages. Can be access under your Appsheet App -> icon that looks like a pulse -> "Monitor" submenu -> "Audit History" -> "Launch log analyzer"

Available Methods

Find Items

  1. Search for a Specific Value in Any Column result = client.find_item("Table Name", "ABC123")
  2. Search for a Specific Vaue in a Specific Column result = client.find_item("Table Name", "ABC123", target_column="column name")

Add Items (New Rows)

rows_to_add = [
    {
        "Generation Date": "1700000000",
        "UserID": "someone@someone.com",
        "Serial Number Hex": "ABC123",
        "SKU": "SKU123",
        "Batch": "Batch01",
    },
    {
        "Generation Date": "1700000001",
        "UserID": "john@doe.com",
        "Serial Number Hex": "DEF456",
        "SKU": "SKU456",
        "Batch": "Batch02",
    }
]


# Add rows to the AppSheet table
response = client.add_item("Inventory Table", rows_to_add)

# Process the response
print("Response from AppSheet API:", response)


Edit Item

Note: when updating an entry, the dictionary's first entry in the row data should be the designated key column (as defined in the AppSheet app settings for that table)

# Example usage of edit_item
serial_number = "ABC123"
sku = "SKU456"

row_data = {
    "Serial Number Hex": serial_number,  # Key column for the table
    "Bar Code": f"Inventory_Images/{serial_number}_serial_barcode.svg",
    "QR Code": f"Inventory_Images/{serial_number}_serial_qr.svg",
    "SKU Bar Code": f"Inventory_Images/{sku}_sku_barcode.svg"
}

response = client.edit_item("Inventory Table", "Serial Number Hex", row_data)

if response.get("status") == "OK":
    print("Row updated successfully with image paths.")
else:
    print(f"Failed to update row. API response: {response}")

Delete Row by Key

# Example: Delete a row by its key
# "Serial Number Hex" is key col name

response = client.delete_row("Inventory Table", "Serial Number Hex", "ABC123") 

Known Limitations and Important Notes

(Contributions Welcome!)

  • Querying for specific rows that contain an item of interest currently pulls all rows and filters locally.
  • Finding items currently pulls all rows and returns it in whatever, but the API does appear to have support for filtering and ordering. See here
  • Appsheet table names, which are used in URL-encoding, are assumed to not contain any special characters other than spaces. I.e. you can supply a table name like "my table" and the library will convert this to "my%20table" as needed under the hood, but does not handle other special characters that may mess with URL-encoding.

Additional Credits

Credit where credit is due. ChatGPT was leveraged extensively to put this together quickly.

Contributing

Contributions are welcome. Please submit pull requests to the dev branch.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_appsheet-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

py_appsheet-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file py_appsheet-0.1.0.tar.gz.

File metadata

  • Download URL: py_appsheet-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.8

File hashes

Hashes for py_appsheet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 267ca4e0468ce3359af3e3bebaa5a5651cfccd0962d7c67d06a7a4d3e9a4a191
MD5 426b41c770c770a1be7815121df7eb14
BLAKE2b-256 8158e72b2abd9237185762b275acd7358b8714b8955cb169f69e5a4013633d93

See more details on using hashes here.

File details

Details for the file py_appsheet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_appsheet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.8

File hashes

Hashes for py_appsheet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a96aa2f26acf2623aa6b863c472a3d5b08a88e412060ca311e19955c2228198f
MD5 77d8868d26b50edd791058a529d4694d
BLAKE2b-256 a16c5436025081445a0b9dfa46f8ec620535598e38ed01c488cc036fffa2c6c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page