Client class for database access

We'll define a simple class for database access. A class can provide context and status information for multiple related operations. When working with the Elastic database, an access class can create the request headers dictionary just once and reuse it in multiple requests.

Here's the essence of a database client class. We'll show this in several sections. First, the overall class definition:

    class ElasticClient: 
        service = "https://api.orchestrate.io" 

This defines a class-level variable, service, with the scheme and hostname. The initialization method, __init__(), can build the headers that are used by the various database operations:

 def __init__(self, api_key, password=''): self.headers = { 'Accept': ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.