{"id":25444094,"url":"https://github.com/pedrohenriquebr/sheetsorm","last_synced_at":"2025-05-16T01:09:37.715Z","repository":{"id":57466745,"uuid":"429909791","full_name":"pedrohenriquebr/sheetsorm","owner":"pedrohenriquebr","description":"SheetORM for Python extension for the Gspread ","archived":false,"fork":false,"pushed_at":"2021-11-20T01:30:46.000Z","size":11,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T22:16:24.945Z","etag":null,"topics":["dataframe","googlesheetsapi","gspread","orm","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pedrohenriquebr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-19T19:18:46.000Z","updated_at":"2021-11-21T22:18:24.000Z","dependencies_parsed_at":"2022-09-10T03:44:52.739Z","dependency_job_id":null,"html_url":"https://github.com/pedrohenriquebr/sheetsorm","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrohenriquebr%2Fsheetsorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrohenriquebr%2Fsheetsorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrohenriquebr%2Fsheetsorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrohenriquebr%2Fsheetsorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pedrohenriquebr","download_url":"https://codeload.github.com/pedrohenriquebr/sheetsorm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448624,"owners_count":22072765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataframe","googlesheetsapi","gspread","orm","python","python3"],"created_at":"2025-02-17T15:19:35.493Z","updated_at":"2025-05-16T01:09:32.701Z","avatar_url":"https://github.com/pedrohenriquebr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SheetsORM\nSheetsORM is a simple micro ORM extension for gspread.\n\nFeatures:\n- Create a entity class for each worksheet\n- Columns are mapped to attributes\n- Repository: Add,Remove,Update operations\n- Type checking for attributes\n\n## Requirements\nPython 3.9+\n\n## Installation\n\n```\npip install sheetsorm\n```\n\n\n## Basic usage\n\n1.[Create credentials in Google API Console](https://docs.gspread.org/en/latest/oauth2.html)\n\n2.Creating an instance:\n```python\n\nfrom sheetsorm.orm import SheetsORM\n\n# Create a SheetsORM instance\ngs = SheetsORM(scope=['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive'],\n        credentials_file='./credentials.json', # pass the path of the credentials file, or google drive URL \n        is_url=False, # True if the credentials file is a google drive URL\n        spreadsheet_name='DEV' # pass the name of the spreadsheet\n        )\n\n# if the spread sheet is not found, it will be created\ngs.connect()\n\n# You should share the spreadsheet with your preferred email address\ngs.share('your@email.com','user','owner')\n```\n\n3.Create a class for each worksheet:\n```python\nfrom sheetsorm.decorators import entity, column\nfrom datetime import datetime\n\n# define the entity\n# the worksheet name by default is the class name\n@entity(worksheet='Kat')\nclass Kat:\n    # our primary key auto_increment with non-nullable values\n    # name defines the column name in the worksheet, by default it is the attribute name\n    id = column(int,name='ID',primary_key=True,increment=True, required=True)\n    # pass the length of the column as argument to 'str'\n    name = column(str(200),name='NAME',required=True)\n    # or use as a string \n    color = column('20',name='COLOR')\n\n\n# the entity decorator add a new constructor that allows you to create an instance\n# from key values\nmeow  = Kat(name='Meow',birth_date=datetime(2019,1,1),color='black')\n\nrepo = gs.get_repository(Kat)\n\n# add the object\nrepo.add(meow)\n# and then commit the changes\nrepo.commit()\n\n# pass lambda function to filter the results\nfind_meow = repo.find(lambda x: x.name=='Meow')\nif len(find_meow) == 1:\n    print('I Found Meow')\n    print(f'His id: {find_meow[0].id}')\n    print(f'His name: {find_meow[0].name}')\n    print(f'His birth date: {find_meow[0].birth_date}')\n    print(f'His color: {find_meow[0].color}')\nelse:\n    print('I did not find Meow')\n\n\nmeow = find_meow[0]\nmeow.name = 'Meow2'\n# Runtime type checkings\n# meow.color  = 1  # TypeError: color must be of type 'str'\nrepo.update(meow)\nrepo.commit()\n\n# Remove the row from the worksheet\nrepo.remove()\nrepo.commit()\n\n# Other functions to use:\n# repo.all(lambda x: x.color=='orange')\n# repo.any(lambda x: x.name=='Mr. Potato')\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriquebr%2Fsheetsorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedrohenriquebr%2Fsheetsorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriquebr%2Fsheetsorm/lists"}