Skip to main content

Zoho Analytics connector

Project description

Zoho Analytics Connector

Zoho's SDK for Zoho Reports is very old, however it is very complete. This is a version which is Python 3 ready, tested on Python 3.7. There are not many test cases yet. It is patched to work: that is, it's been made Python 3.7 compatible with the least amount of effort.

A more convenient wrapper class is in enhanced_report_client.

This is still Beta, but I have used it extensively in production. Beta because I don't use all of the API, and there are no test cases that cover the entire API.

I use it mostly for uploading data, and creating and modifying tables, at this point.

Zoho updated the 2.7 code with oauth support, as the old tokens are deprecated. I have merged this code into my library, but I have not tested it yet.

Authentication

Authentication is easy. You log in and visit a URL to gain a token, which does not expire. This is deprecated in favour of oauth. V 0.3.0 has Zoho's oauth changes, but I haven't tested them yet.

Read more here https://www.zoho.com/analytics/api/#prerequisites

Usage

Zoho's full API is available through the ReportClient API.

EnhancedZohoAnalyticsClient is a higher level layer.

The tests show how to use it:

Setup necessary values (database is the Z.A. Workspace name)

Config class is used in the testcases as a convenience.

class Config:
    LOGINEMAILID = os.getenv('ZOHOANALYTICS_LOGINEMAIL')
    AUTHTOKEN = os.getenv('ZOHOANALYTICS_AUTHTOKEN')
    DATABASENAME = os.getenv('ZOHOANALYTICS_DATABASENAME')

Make the API instance:

def get_enhanced_zoho_analytics_client()->EnhancedZohoAnalyticsClient:
    if (Config.AUTHTOKEN == ""):
        raise RuntimeError(Exception, "Please configure AUTHTOKEN in Config class")
    rc = EnhancedZohoAnalyticsClient(login_email_id = Config.LOGINEMAILID,
                                     authtoken=Config.AUTHTOKEN, default_databasename=Config.DATABASENAME)
    return rc

Do some stuff:

def test_get_database_metadata(get_enhanced_zoho_analytics_client):
    enhanced_rc = get_enhanced_zoho_analytics_client
    table_meta_data = enhanced_rc.get_table_metadata()
    assert table_meta_data


def test_data_upload(get_enhanced_zoho_analytics_client:EnhancedZohoAnalyticsClient):
    try:
        with open('StoreSales.csv', 'r') as f:
            import_content = f.read()
    except Exception as e:
        print("Error Check if file StoreSales.csv exists in the current directory!! ", str(e))
        return
        # import_modes = APPEND / TRUNCATEADD / UPDATEADD
    impResult = get_enhanced_zoho_analytics_client.data_upload(import_content=import_content,table_name="sales")
    assert(impResult)

    try:
        with open('Animals.csv', 'r') as f:
            import_content2 = f.read()
    except Exception as e:
        print("Error Check if file Animals.csv exists in the current directory!! ", str(e))
        return
    impResult2 = get_enhanced_zoho_analytics_client.data_upload(import_content=import_content2, table_name="animals")
    assert (impResult2)

#Run SQL. You can join tables. The rows are returned as a DictReader. If you pass ' characters into IN(...) clauses, you need to escape them yourself (double ')

def test_data_download(get_enhanced_zoho_analytics_client):
    sql="select * from sales"
    result = get_enhanced_zoho_analytics_client.data_export_using_sql(sql=sql,table_name="sales")
    assert result

    #the table name does not matter
    sql="select * from animals"
    result = get_enhanced_zoho_analytics_client.data_export_using_sql(sql=sql,table_name="sales")
    assert result


#create a table

zoho_sales_fact_table = {
    'TABLENAME': 'sales_fact',
    'COLUMNS': [
        {'COLUMNNAME':'inv_date', 'DATATYPE':'DATE'},
        {'COLUMNNAME':'customer', 'DATATYPE':'PLAIN'},
        {'COLUMNNAME':'sku', 'DATATYPE':'PLAIN'},
        {'COLUMNNAME':'qty_invoiced', 'DATATYPE':'NUMBER'},
        {'COLUMNNAME':'line_total_excluding_tax', 'DATATYPE':'NUMBER'}]
    }

def test_create_table(get_enhanced_zoho_analytics_client):
    #is the table already defined?
    try:
        zoho_table_metadata = get_enhanced_zoho_analytics_client.get_table_metadata()
    except  ServerError as e:
        if getattr(e, 'message') == 'No view present in the workspace.':
            zoho_table_metadata = {}
        else:
            raise
    zoho_tables = set(zoho_table_metadata.keys())

    if "sales_fact" not in zoho_tables:
        get_enhanced_zoho_analytics_client.create_table(table_design=zoho_sales_fact_table)
    else:
        #get an error, but error handling is not working, the API returns a 400 with no content in the message
        r = get_enhanced_zoho_analytics_client.create_table(table_design=zoho_sales_fact_table)
        print (r)

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

zoho_analytics_connector-0.3.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

zoho_analytics_connector-0.3.1-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file zoho_analytics_connector-0.3.1.tar.gz.

File metadata

  • Download URL: zoho_analytics_connector-0.3.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for zoho_analytics_connector-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fa87f27abfc6d4938e0491b78a25177f5b2b3852e2677670b3a37817907d6722
MD5 2ee782162f242e92abbba625484d930d
BLAKE2b-256 15a6ee61e2221835a8c2fb1dfd75cccaf01aa93bafd504917e688af5ea4ad64c

See more details on using hashes here.

File details

Details for the file zoho_analytics_connector-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: zoho_analytics_connector-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for zoho_analytics_connector-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0efb08c3dcb597fc5783b1b511a4c9a64b37af42fe4b0aad7c08391c368a931c
MD5 3476ef480647275534068cd1565ed934
BLAKE2b-256 6446244599d85b8d48ce9daa734fc91b5408474bfc9e615c0d0270ceba53b145

See more details on using hashes here.

Supported by

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