Helper library for easier creation of Google services.
Project description
Python Library for helping to create Python services from Google APIs
Something I have to do a lot is create connections to Google Service endpoints. This generally requires a fair amount of boiler-plate code that io just copied and pasted from other locations. Also any time a new service is needed, I need to find that specific implementation of the service builder and add the new endpoint.
Obviously this can lead to potential errors and if a bug is found, I have to remember where I created these services and fix it in many projects.
This has led me to create a small helper library to make the process easier.
Included in the library is a complete and updated (at time of publishing) list
of all the Google APIs along with their versions and endpoints as Enum
s
ready for use.
Usage
service_builder.build_service()
needs two mandatory pieces of information:
Parameter | Description |
---|---|
key | The credentials to use to authenticate the user to the service it has to create |
service | The Google API endpoint it is trying to connect to. |
key
These can be supplied in one of 4 ways.
- A valid
google.oauth2.Credentials
object, created and passed to the service builder. - An
str
which is the name of a local file containing thejson
representation of an OAuth credentials object. - A
Mapping
object which is ajson
keyfiledict
- An
OAuthKey
object from this package, which is adataclass
object comprising of the minimum fields necessary to perform the OAuth connection.
service
This is an Enum in the service_framework.service
module, which defines
the Google service you're planning to connect to. All of these services are
dynamically built, but their names match the Google-defined name.
Example
from service_framework.services import Service
from service_framework import service_builder
key = service_builder.OAuthKey(
access_token="<YOUR ACCESS TOKEN>",
refresh_token="<YOUR REFRESH TOKEN>",
token_uri="https://oauth2.googleapis.com/token",
client_id="<YOUR CLIENT ID>",
client_secret="<YOUR CLIENT SECRET>"
)
service = service_builder.build_service(service=Service.GMAIL, key=key)
Here, we are creating the key as an OAuthKey
object as we have clearly got the
tokens and client_[id|secret] from elsewhere. Creating the service is then as
simple as invoking the service_builder.build_service
method which will return
you a service you can use.
Other parameters
service_builder.build_service()
can also take 2 other optional parameters.
Parameter | Description |
---|---|
api_key | Some APIs require an API key as well as the OAuth credentials |
extra_scopes | Any extra OAUth scopes required for the operation |
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
Built Distribution
File details
Details for the file python-service-builder-1.0.2.tar.gz
.
File metadata
- Download URL: python-service-builder-1.0.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c616298f04f76910c15352b218b70d184678c17759b548deb2dbcedb446f74 |
|
MD5 | a7b44ef98ce53ef2e0f040da4f285d3e |
|
BLAKE2b-256 | a60dd5d70dac4f13f20e6815f944e0d3b643f09c086686ed01335648c8dc5e1f |
File details
Details for the file python_service_builder-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: python_service_builder-1.0.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2559671df6f946935e08743dffbf9b032b9610058411d25854146b625c6d32c1 |
|
MD5 | 9af9610107e69313e41c6cce54c2030a |
|
BLAKE2b-256 | ed1cc5750fbb2b15baf0888441d2384317df2fcc218749db50b06dee3f327ec0 |