Skip to main content

gsuite-meld

'gsuite-meld' is an Python package designed to facilitate seamless integration with a variety of GSuite services, including Google Sheets, Docs, and Drive, and is extensible to accommodate future GSuite additions. The package leverages the power of Python's metaclasses to simplify interfacing with Google APIs, thus allowing users to effortlessly build and manage multi-service workflows.

Core Features

  • Unified GSuite Interface: Our package encapsulates the functionality of Google Sheets, Google Docs, and Google Drive into three primary classes: Sheet, Document, and Drive. These classes are endowed with a rich set of methods, enabling users to handle various operations such as downloads, uploads, deletions, and updates.
  • Batch Operations: We recognize that efficiency is paramount in managing your data. Therefore, we've designed gsuite-meld to perform operations in batches, providing significant time savings for large-scale data handling.
  • Iterative Content Access: With gsuite-meld, users can iterate over the content of sheets and documents, thus simplifying data manipulation within the Python environment.
  • Dynamic API Builder: The GoogleAPI metaclass dynamically builds the API service needed for each object. This feature takes advantage of Python's metaclass capabilities to reduce the redundancy in API creation and to keep the codebase clean and efficient.
  • Flexible Credentials Management: To ensure secure and flexible integration, gsuite-meld requires users to supply GSuite credentials, which can be provided as a file, a dictionary, or a JSON parseable string set as an environment variable.

Limitations

  • Gsuite-meld is not a general-purpose Google API package; it specifically targets GSuite services.
  • While we strive to cover a wide range of functions, some more complex features may not be supported by this package.
  • Users need to be familiar with Google Sheets, Google Docs, and Google Drive IDs and understand how to obtain them.

Overall, gsuite-meld offers a user-friendly and effective way to navigate the diverse ecosystem of GSuite services. Whether you're managing data in Sheets, creating documents, or organizing files on Drive, gsuite-meld can streamline your workflow.

Requirements

  • Python 3.6 or higher
  • google-auth 1.6.3 or higher
  • google-auth-httplib2 0.0.3 or higher
  • google-auth-oauthlib 0.4.1 or higher
  • google-api-python-client 1.7.11 or higher

Installation

  • Use the package manager pip to install gsuite_meld.
pip install gsuite_meld

Usage

The gsuite_meld package contains tree modules: Sheet, Document and Drive.

Drive.py

from gsuite_meld import Drive

drive = Drive()
drive.download_file("file_id", "/path/to/save")

Document.py

from gsuite_meld import Document

doc = Document() # Create an instance of the Document class
doc.create("My New Document") # Create a new Google Document with a specified name
doc.download() # Download the contents of the newly created document into memory

Creating Multiple Documents:

for i in range(5):
    doc.create(f"My Document {i+1}")

Getting a Document's JSON Representation:

doc.create("My New Document")
doc.download()
json_content = doc.as_json()
print(json_content)

Overwriting Multiple Documents with New Content:

document_ids = ["id1", "id2", "id3"]
new_content = "This is the new content of the document"
for document_id in document_ids:
    doc.upload(content=new_content, document_id=document_id)

Combining Multiple Documents' Content into One Document:

document_ids = ["id1", "id2", "id3"]
combined_content = ""
for document_id in document_ids:
    doc.download(document_id=document_id)
    combined_content += doc.as_txt()
doc.create("Combined Document")
doc.upload(content=combined_content)

Accessing the Content of a Document Line by Line:

doc.create("My New Document")
doc.upload("Line 1\nLine 2\nLine 3")
doc.download()
for line in doc:
    print(line)

Sheet.py

from gsuite_meld import Sheet

sheet = Sheet()
sheet.download("spreadsheet_id", "worksheet_name")

Download a Worksheet:

sheet = Sheet()
sheet.download("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", "Data")

Download Multiple Worksheets:

sheet = Sheet()
sheets_content = sheet.batch_download("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", ["Data", "Description"])

Create a Google Spreadsheet:

sheet = Sheet()
body = {
    'properties': {
        'title': 'New Google Sheet'
    }
}
sheet.create(body)

Add Multiple Worksheets:

sheet = Sheet()
sheet.batch_add("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", ["Worksheet 1", "Worksheet 2"])

Clear a Worksheet:

sheet = Sheet()
sheet.clear("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", "Worksheet 1")

Update a Worksheet:

sheet = Sheet()
new_data = [['John', 'Doe', '123 Street', 'City'], ['Jane', 'Doe', '456 Street', 'City']]
sheet.update("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", "Worksheet 1", new_data)

Protect a Worksheet:

sheet = Sheet()
body = {
    "requests": [
        {
            "addProtectedRange": {
                "protectedRange": {
                    "range": {
                        "sheetId": 1,
                        "startRowIndex": 0,
                        "startColumnIndex": 0,
                        "endColumnIndex": 1
                    },
                    "description": "Protecting date column from changes.",
                    "warningOnly": True,
                }
            }
        }
    ]
}
sheet.protect("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", body)

Delete Multiple Worksheets:

sheet = Sheet()
sheet.batch_delete("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", [0, 1])

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache 2.0

Metadata

Release files for gsuite-meld 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gsuite-meld 0.0.1
File Size Uploaded
gsuite_meld-0.0.1.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gsuite-meld 0.0.1
File Interpreter ABI Platform
gsuite_meld-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / gsuite_meld-0.0.1.tar.gz

Download URL gsuite_meld-0.0.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
445b823ef4ddd7e83187d1fe13bebaaa7978e96d1623f52791f1ac36aed25f2c
BLAKE2b-256 checksum
How to use checksums
d77a5e9a46aac859944d0e87670cc5f8289aaa702dcbcf35501977c8bd3a086c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / gsuite_meld-0.0.1-py3-none-any.whl

Download URL gsuite_meld-0.0.1-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
836cc7631900f64e170f069522889d59527c6dabaaa2aa804b89e54a65b32981
BLAKE2b-256 checksum
How to use checksums
43b155bceb9addb4f4ba0b325e06b59f321453376f25afff4478f0e7829654c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page