Skip to main content

Convenient integration with Google Services

Project description

♡ Nexium Google

Welcome to the documentation for the nexium_google module. This module provides functionality for interacting with various Google services, including Spreadsheet and YouTube.

Table of Contents:

  1. Introduction
  2. Installation
  3. Spreadsheet
  4. YouTube
  5. Conclusion
  6. License

Introduction

The nexium_google module is a powerful tool for interacting with various services using Python. This module is asynchronous and leverages the Google API to provide an abstract interface for performing operations with Google services.

Installation

To install the nexium_google module, you can use pip.

pip install nexium_google

Spreadsheet

Setting up a Spreadsheet instance

At this point, make sure you have your Google Cloud Service account credentials and the necessary permissions to access Google Sheets. You will need a JSON file with your credentials as well as the Google Sheet ID.

Now, we need to initialize a Spreadsheet instance using your service account and sheet ID.

from nexium_google.utils import ServiceAccount
from nexium_google.spreadsheet import Spreadsheet

google_sheet = Spreadsheet(
   service_account=ServiceAccount(filename='creds.json'),
   id_='your-spreadsheet-id',
   models=[],
)

Configuring a Row model

The BaseRowModel functionality allows you to define models for the structure of your Google Sheet, similar to how ORM platforms work with databases. This includes defining columns and their types in Python, such as:

  • String
  • Integer
  • Float
  • DateTime
  • Boolean

At this stage, ensure that the corresponding sheet in Google Sheets is already created. Additionally, the title in the Field must match the column name exactly.

from nexium_google.spreadsheet import BaseRowModel, Field, FieldType

class UserRowModel(BaseRowModel):
    __sheet__ = 'Users'
    id = Field(title='ID', type_=FieldType.INTEGER, nullable=False)
    fullname = Field(title='Full Name', type_=FieldType.STRING, nullable=False)
    salary = Field(title='Salary', type_=FieldType.FLOAT)
    created_at = Field(title='DateTime', type_=FieldType.DATETIME, format_='%Y-%m-%d %H:%M')

Once you've created all the necessary models, add them to the models field in the Spreadsheet instance you previously initialized. This will link the sheets to your table.

Usage example

from asyncio import run, sleep
from datetime import datetime

from nexium_google.utils import ServiceAccount
from nexium_google.spreadsheet import Spreadsheet
from nexium_google.spreadsheet import BaseRowModel, Field, FieldType


class UserRowModel(BaseRowModel):
    __sheet__ = 'Users'
    id = Field(title='ID', type_=FieldType.INTEGER, nullable=False)
    fullname = Field(title='Full Name', type_=FieldType.STRING, nullable=False)
    salary = Field(title='Salary', type_=FieldType.FLOAT)
    created_at = Field(title='DateTime', type_=FieldType.DATETIME, format_='%Y-%m-%d %H:%M')


google_sheet = Spreadsheet(
    service_account=ServiceAccount(filename='creds.json'),
    id_='your-spreadsheet-id',
    models=[UserRowModel],
)


async def main():
    # Create new user
    user = UserRowModel(
        id=3,
        fullname='Yegor Yakubovich',
        salary=1000000,
        created_at=datetime.now(),
    )
    await user.create()
    await sleep(2)

    # Get all users
    for user in await UserRowModel().get_all():
        # Print data
        print(f'Full Name: {user.fullname}, Salary: {user.salary}')

        # Update salary
        if user.id == 3:
            continue

        user.salary = 0
        await user.update()
        await sleep(1)


if __name__ == '__main__':
    run(main())

The example below demonstrates an algorithm where a new user is added, followed by a for loop iterating through all users to update their salaries. Spreadsheet

YouTube

In Development

Conclusion

The nexium_google module's Spreadsheet functionality provides a powerful and flexible way to manage Google Spreadsheets in Python. By defining models and leveraging asynchronous methods, you can efficiently perform CRUD operations on your spreadsheets.

Feel free to explore and expand the capabilities of the module to suit your specific needs. Good luck! ♡

License

This project is licensed under the MIT License. See the LICENSE file for details.

Copyright © 2024 Yegor Yakubovich

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

nexium_google-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexium_google-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nexium_google-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f1b424d3c27354e96ce200f543108fae4b0ea3f2474a976d9ba5f26faea14d84
MD5 d9016c2adaea03955d9d400e4da7f2b8
BLAKE2b-256 e113dbaaff0e133dff8f263f85880779755667844cae2b156617d3f4335b95e3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nexium_google-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af68dce663289f0a83e90c529d7aea7f07b71efb9bfd5f2757a9e659798dc81d
MD5 f57134f5cea12a8984144169b481559c
BLAKE2b-256 c55a5f875504bbce951e670ec9e3258eb349a9e0c4238f0bf10f4d6928d0066a

See more details on using hashes here.

Supported by

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