google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Type and document your google meet api properly

Open jefer94 opened this issue 1 year ago • 9 comments

Determine this is the right repository

  • [X] I determined this is the correct repository in which to report this bug.

Summary of the issue

Related to type the API properly

image

image

image

Why is this important

I am sure that this issue was caused by bad typing https://github.com/microsoft/pylance-release/issues/6417

Related to document the API properly

The docs don't have any reference for arguments, returns, or how the elements are related, the only docs that worked aren't here https://developers.google.com/meet/api/guides/meeting-spaces it's in the docstring

API client name and version

==0.1.8

Reproduction steps: code

file: main.py

   def reproduce():
    # complete code here

Reproduction steps: supporting files

import os.path
from typing import Optional, TypedDict, Unpack, AsyncIterator
from google.apps.meet_v2 import ConferenceRecord

import google.apps.meet_v2.services.conference_records_service.pagers as pagers
from asgiref.sync import async_to_sync
from google.apps import meet_v2
from google.apps.meet_v2.types import Space
from google.protobuf.field_mask_pb2 import FieldMask
from google.oauth2.credentials import Credentials


import pickle
from google.auth.transport.requests import Request

__all__ = ["GoogleMeet"]


class CreateSpaceRequest(TypedDict):
    space: Space


class EndActiveConferenceRequest(TypedDict):
    name: str


class GetConferenceRecordRequest(TypedDict):
    name: str


class GetParticipantRequest(TypedDict):
    name: str


class GetParticipantSessionRequest(TypedDict):
    name: str


class GetRecordingRequest(TypedDict):
    name: str


class GetSpaceRequest(TypedDict):
    name: str


class UpdateSpaceRequest(TypedDict):
    space: Space
    update_mask: FieldMask


class GetTranscriptRequest(TypedDict):
    name: str


class ListConferenceRecordsRequest(TypedDict):
    page_size: int
    page_token: str
    filter: str  # in EBNF format, space.meeting_code, space.name, start_time and end_time


class ListRecordingsRequest(TypedDict):
    parent: str
    page_size: int
    page_token: str


class ListParticipantSessionsRequest(TypedDict):
    parent: str
    page_size: int
    page_token: str
    filter: str  # in EBNF format, start_time and end_time


class ListTranscriptsRequest(TypedDict):
    parent: str
    page_size: int
    page_token: str


class ListParticipantsRequest(TypedDict):
    parent: str
    page_size: int
    page_token: str
    filter: str  # in EBNF format, start_time and end_time


class ListTranscriptEntriesRequest(TypedDict):
    parent: str
    page_size: int
    page_token: str


class GetTranscriptEntryRequest(TypedDict):
    name: str


# Scopes for Google Calendar API (used for creating Google Meet links)
# https://www.googleapis.com/auth/meetings.space.created
# https://www.googleapis.com/auth/meetings.space.readonly
# SCOPES = [
#     "google.apps.meet.v2.SpacesService.CreateSpace",
#     "google.apps.meet.v2.SpacesService.GetSpace",
# ]
TOKEN_FILE_NAME = "google_cloud_oauth_token.pickle"
GOOGLE_CLIENT_SECRET = "client_secret.json"


class GoogleMeet:
    _spaces_service_client: Optional[meet_v2.SpacesServiceAsyncClient]
    _conference_records_service_client: Optional[meet_v2.ConferenceRecordsServiceAsyncClient]

    def __init__(self, token: str, refresh_token: Optional[str] = None):
        self._credentials = self._get_credentials(token, refresh_token)
        self._spaces_service_client = None
        self._conference_records_service_client = None

    def _get_credentials(
        self, token: Optional[str] = None, refresh_token: Optional[str] = None
    ) -> Optional[Credentials]:
        creds = None

        if token:
            creds = Credentials(
                token=token,
                refresh_token=refresh_token,
                token_uri="https://oauth2.googleapis.com/token",
                client_id=os.getenv("GOOGLE_CLIENT_ID"),
                client_secret=os.getenv("GOOGLE_SECRET"),
            )
            creds.refresh(Request())
        elif os.path.exists(TOKEN_FILE_NAME):
            with open(TOKEN_FILE_NAME, "rb") as token:
                creds = pickle.load(token)
                creds.refresh(Request())

        # If there are no valid credentials available, raise an exception
        if not creds or not creds.valid:
            if creds and creds.expired and creds.refresh_token:
                creds.refresh(Request())
            else:
                raise Exception("Invalid or expired credentials. Please provide a valid token.")

        return creds

    async def spaces_service_client(self):
        if self._spaces_service_client is None:
            self._spaces_service_client = meet_v2.SpacesServiceAsyncClient(credentials=self._credentials)

        return self._spaces_service_client

    async def conference_records_service_client(self):
        if self._conference_records_service_client is None:
            self._conference_records_service_client = meet_v2.ConferenceRecordsServiceAsyncClient(
                credentials=self._credentials
            )

        return self._conference_records_service_client

    async def acreate_space(self, **kwargs: Unpack[CreateSpaceRequest]) -> meet_v2.Space:

        # Create a client
        client = await self.spaces_service_client()

        # Initialize request argument(s)
        request = meet_v2.CreateSpaceRequest(**kwargs)

        # Make the request
        return await client.create_space(request=request)

    @async_to_sync
    async def create_space(self, **kwargs: Unpack[CreateSpaceRequest]) -> meet_v2.Space:
        return await self.acreate_space(**kwargs)

    async def aget_space(self, **kwargs: Unpack[GetSpaceRequest]) -> meet_v2.Space:

        # Create a client
        client = await self.spaces_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetSpaceRequest(**kwargs)

        # Make the request
        response = await client.get_space(request=request)

        # Handle the response
        print(response)

    @async_to_sync
    async def get_space(self, **kwargs: Unpack[GetSpaceRequest]) -> meet_v2.Space:
        return await self.aget_space(**kwargs)

    async def aupdate_space(self, **kwargs: Unpack[UpdateSpaceRequest]) -> meet_v2.Space:
        # Create a client
        client = await self.spaces_service_client()

        # Initialize request argument(s)
        request = meet_v2.UpdateSpaceRequest(**kwargs)

        # Make the request
        response = await client.update_space(request=request)

        # Handle the response
        print(response)

    @async_to_sync
    async def update_space(self, **kwargs: Unpack[UpdateSpaceRequest]) -> meet_v2.Space:
        return await self.aupdate_space(**kwargs)

    async def aend_active_conference(self, **kwargs: Unpack[EndActiveConferenceRequest]) -> None:
        # Create a client
        client = await self.spaces_service_client()

        # Initialize request argument(s)
        request = meet_v2.EndActiveConferenceRequest(**kwargs)

        # Make the request
        return await client.end_active_conference(request=request)

    @async_to_sync
    async def end_active_conference(self, **kwargs: Unpack[EndActiveConferenceRequest]) -> None:
        return await self.aend_active_conference(**kwargs)

    async def alist_participants(self, **kwargs: Unpack[ListParticipantsRequest]) -> pagers.ListParticipantsAsyncPager:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListParticipantsRequest(**kwargs)

        # Make the request
        return await client.list_participants(request=request)

    async def aget_participant(self, **kwargs: Unpack[GetParticipantRequest]) -> meet_v2.Participant:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetParticipantRequest(**kwargs)

        # Make the request
        return await client.get_participant(request=request)

    @async_to_sync
    async def get_participant(self, **kwargs: Unpack[GetParticipantRequest]) -> meet_v2.Participant:
        return await self.aget_participant(**kwargs)

    async def alist_participant_sessions(
        self, **kwargs: Unpack[ListParticipantSessionsRequest]
    ) -> pagers.ListParticipantSessionsAsyncPager:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListParticipantSessionsRequest(**kwargs)

        # Make the request
        return await client.list_participant_sessions(request=request)

    async def aget_participant_session(
        self, **kwargs: Unpack[GetParticipantSessionRequest]
    ) -> meet_v2.ParticipantSession:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetParticipantSessionRequest(**kwargs)

        # Make the request
        return await client.get_participant_session(request=request)

    @async_to_sync
    async def get_participant_session(
        self, **kwargs: Unpack[GetParticipantSessionRequest]
    ) -> meet_v2.ParticipantSession:
        return await self.aget_participant_session(**kwargs)

    async def alist_recordings(self, **kwargs: Unpack[ListRecordingsRequest]) -> pagers.ListRecordingsAsyncPager:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListRecordingsRequest(**kwargs)

        # Make the request
        return await client.list_recordings(request=request)

    async def aget_recording(self, **kwargs: Unpack[GetRecordingRequest]) -> meet_v2.Recording:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetRecordingRequest(**kwargs)

        # Make the request
        response = await client.get_recording(request=request)

        # Handle the response
        print(response)

    @async_to_sync
    async def get_recording(self, **kwargs: Unpack[GetRecordingRequest]) -> meet_v2.Recording:
        return await self.aget_recording(**kwargs)

    async def alist_transcripts(self, **kwargs: Unpack[ListTranscriptsRequest]) -> pagers.ListTranscriptsAsyncPager:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListTranscriptsRequest(**kwargs)

        # Make the request
        return await client.list_transcripts(request=request)

    async def alist_transcript_entries(
        self, **kwargs: Unpack[ListTranscriptEntriesRequest]
    ) -> pagers.ListTranscriptEntriesAsyncPager:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListTranscriptEntriesRequest(**kwargs)

        # Make the request
        return await client.list_transcript_entries(request=request)

    async def aget_transcript(self, **kwargs: Unpack[GetTranscriptRequest]) -> meet_v2.Transcript:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetTranscriptRequest(**kwargs)

        # Make the request
        response = await client.get_transcript(request=request)

        # Handle the response
        print(response)

    @async_to_sync
    async def get_transcript(self, **kwargs: Unpack[GetTranscriptRequest]) -> meet_v2.Transcript:
        return await self.aget_transcript(**kwargs)

    async def aget_transcript_entry(self, **kwargs: Unpack[GetTranscriptEntryRequest]) -> meet_v2.TranscriptEntry:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetTranscriptEntryRequest(**kwargs)

        # Make the request

        return await client.get_transcript_entry(request=request)

    @async_to_sync
    async def get_transcript_entry(self, **kwargs: Unpack[GetTranscriptEntryRequest]) -> meet_v2.TranscriptEntry:
        return await self.aget_transcript_entry(**kwargs)

    async def alist_conference_records(
        self, **kwargs: Unpack[ListConferenceRecordsRequest]
    ) -> pagers.ListConferenceRecordsAsyncPager:

        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.ListConferenceRecordsRequest(**kwargs)

        # Make the request
        pager = await client.list_conference_records(request=request)
        return pager

    async def aget_conference_record(self, **kwargs: Unpack[GetConferenceRecordRequest]) -> meet_v2.ConferenceRecord:
        # Create a client
        client = await self.conference_records_service_client()

        # Initialize request argument(s)
        request = meet_v2.GetConferenceRecordRequest(**kwargs)

        # Make the request
        return await client.get_conference_record(request=request)

    @async_to_sync
    async def get_conference_record(self, **kwargs: Unpack[GetConferenceRecordRequest]) -> meet_v2.ConferenceRecord:
        return await self.aget_conference_record(**kwargs)

Reproduction steps: actual results

file: output.txtmydata.csv

Calculated: foo

Reproduction steps: expected results

To have good docs and typing

OS & version + platform

Linux Jeferson 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux

Python environment

Python 3.12.5

Python dependencies

Package Version


activecampaign-python 1.0.10 adrf 0.1.7 aiodns 3.2.0 aiohappyeyeballs 2.4.0 aiohttp 3.10.5 aiohttp-retry 2.8.3 aiosignal 1.3.1 amqp 5.2.0 aniso8601 9.0.1 annotated-types 0.7.0 anyio 4.6.0 asgiref 3.8.1 async-property 0.2.2 async-timeout 4.0.3 attrs 24.2.0 autobahn 24.4.2 Automat 24.8.1 babel 2.16.0 beautifulsoup4 4.12.3 billiard 4.2.1 black 24.8.0 bleach 6.1.0 Brotli 1.1.0 cachetools 5.5.0 capy-core 1.0.2 celery 5.4.0 celery-task-manager 1.8.0 certifi 2024.8.30 cffi 1.17.1 cfgv 3.4.0 channels 4.1.0 channels-redis 4.2.0 charset-normalizer 3.3.2 circuitbreaker 2.0.0 click 8.1.7 click-didyoumean 0.3.1 click-plugins 1.1.1 click-repl 0.3.0 colorama 0.4.6 constantly 23.10.4 contextlib2 21.6.0 coralogix-logger 2.0.6 coverage 7.6.1 coveralls 4.0.1 cryptography 43.0.1 cssselect 1.2.0 cssutils 2.11.1 currencies 2020.12.12 daphne 4.1.2 defusedxml 0.7.1 Deprecated 1.2.14 distlib 0.3.8 distro 1.9.0 dj-database-url 2.2.0 Django 5.1.1 django-appconf 1.0.6 django-cors-headers 4.4.0 django-cryptography-django5 2.2 django-heroku 0.3.1 django-minify-html 1.9.0 django-phonenumber-field 8.0.0 django-redis 5.4.0 django-sql-explorer 5.2 django-storages 1.14.4 djangorestframework 3.15.2 djangorestframework-csv 3.0.2 dnspython 2.6.1 docopt 0.6.2 drf-yasg 1.21.7 eventbrite 3.3.5 eventlet 0.37.0 exceptiongroup 1.2.2 execnet 2.1.1 expiringdict 1.2.2 Faker 12.0.1 fastjsonschema 2.20.0 filelock 3.16.1 flake8 7.1.1 flake8-bugbear 24.8.19 flake8-docstrings 1.7.0 frozenlist 1.4.1 gevent 24.2.1 ghp-import 2.1.0 google-api-core 2.20.0 google-api-python-client 2.146.0 google-apps-meet 0.1.8 google-auth 2.35.0 google-auth-httplib2 0.2.0 google-auth-oauthlib 1.2.1 google-cloud-bigquery 3.25.0 google-cloud-bigquery-storage 2.26.0 google-cloud-core 2.4.1 google-cloud-datastore 2.20.1 google-cloud-firestore 2.18.0 google-cloud-ndb 2.3.2 google-cloud-recaptcha-enterprise 1.22.1 google-cloud-storage 2.18.2 google-crc32c 1.6.0 google-resumable-media 2.7.2 googleapis-common-protos 1.65.0 graphene 3.3 graphene-django 3.2.2 graphene-django-optimizer 0.10.0 graphql-core 3.2.4 graphql-relay 3.2.0 greenlet 3.1.1 griffe 1.3.1 grpcio 1.66.1 grpcio-status 1.66.1 gunicorn 23.0.0 h11 0.14.0 h2 4.1.0 hiredis 3.0.0 hpack 4.0.0 httpcore 1.0.5 httplib2 0.22.0 httptools 0.6.1 httpx 0.27.2 hyperframe 6.0.1 hyperlink 21.0.0 icalendar 5.0.13 identify 2.6.1 idna 3.10 importlib_metadata 8.0.0 incremental 24.7.2 inflection 0.5.1 iniconfig 2.0.0 Jinja2 3.1.4 jiter 0.5.0 jsonschema 4.23.0 jsonschema-specifications 2023.12.1 jupyter_client 8.6.3 jupyter_core 5.7.2 jupyterlab_pygments 0.3.0 kombu 5.4.2 launchdarkly-eventsource 1.2.0 launchdarkly-server-sdk 9.7.1 linked-services 1.2.3 lxml 5.3.0 Markdown 3.7 MarkupSafe 2.1.5 mccabe 0.7.0 mergedeep 1.3.4 minify_html 0.15.0 mistune 3.0.2 mixer 7.2.2 mkdocs 1.6.1 mkdocs-autorefs 1.2.0 mkdocs-get-deps 0.2.0 mkdocs-material 9.5.36 mkdocs-material-extensions 1.3.1 mkdocstrings 0.26.1 mkdocstrings-python 1.11.1 more-itertools 10.5.0 msgpack 1.1.0 multidict 6.1.0 mypy 1.11.2 mypy-extensions 1.0.0 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 newrelic 9.13.0 nodeenv 1.9.1 numpy 2.1.1 oauthlib 3.2.2 openai 1.47.0 packaging 24.1 paginate 0.5.7 pandas 2.2.3 pandocfilters 1.5.1 pathspec 0.12.1 pep8-naming 0.14.1 phonenumberslite 8.13.45 pillow 10.4.0 pip 24.2 platformdirs 4.3.6 pluggy 1.5.0 pre-commit 3.8.0 premailer 3.10.0 priority 1.3.0 promise 2.3 prompt_toolkit 3.0.47 proto-plus 1.24.0 protobuf 5.28.2 psycopg 3.2.2 psycopg-binary 3.2.2 psycopg-pool 3.2.3 psycopg2 2.9.9 pyarrow 17.0.0 pyasn1 0.6.1 pyasn1_modules 0.4.1 pycares 4.4.0 pycodestyle 2.12.1 pycparser 2.22 pydantic 2.9.2 pydantic_core 2.23.4 pydocstyle 6.3.0 pyfcm 2.0.7 pyflakes 3.2.0 PyGithub 2.4.0 Pygments 2.18.0 PyJWT 2.9.0 pymdown-extensions 10.9 pymemcache 4.0.0 PyNaCl 1.5.0 pyOpenSSL 24.2.1 pyparsing 3.1.4 pyRFC3339 1.1 pyright 1.1.381 pytest 8.3.3 pytest-asyncio 0.24.0 pytest-cov 5.0.0 pytest-django 4.9.0 pytest-env 1.1.5 pytest-gevent 1.1.0 pytest-xdist 3.6.1 python-dateutil 2.9.0.post0 python-dotenv 1.0.1 python-frontmatter 1.1.0 python-magic 0.4.27 python-slugify 8.0.4 pytz 2024.2 PyYAML 6.0.2 pyyaml_env_tag 0.1 pyzmq 26.2.0 redis 5.0.8 referencing 0.35.1 regex 2024.9.11 requests 2.32.3 requests-oauthlib 2.0.0 rpds-py 0.20.0 rsa 4.9 schema 0.7.7 semver 3.0.2 serpy 0.3.1 service-identity 24.1.0 setuptools 75.1.0 six 1.16.0 sniffio 1.3.1 snowballstemmer 2.2.0 soupsieve 2.6 SQLAlchemy 1.4.54 sqlalchemy-bigquery 1.11.0 sqlparse 0.5.1 stripe 10.12.0 text-unidecode 1.3 timeago 1.0.16 tinycss2 1.3.0 tomli 2.0.1 tornado 6.4.1 tqdm 4.66.5 traitlets 5.14.3 twilio 9.3.1 Twisted 24.7.0 txaio 23.1.1 typing_extensions 4.12.2 tzdata 2024.1 uritemplate 4.1.1 urllib3 2.2.3 uvicorn 0.30.6 uvicorn-worker 0.2.0 uvloop 0.20.0 vine 5.1.0 virtualenv 20.26.5 watchdog 5.0.2 watchfiles 0.24.0 wcwidth 0.2.13 webencodings 0.5.1 websockets 13.0.1 whitenoise 6.7.0 wrapt 1.16.0 XlsxWriter 3.2.0 yarl 1.11.1 zipp 3.19.2 zope.event 5.0 zope.interface 7.0.3 zstandard 0.23.0

jefer94 avatar Sep 23 '24 19:09 jefer94