visier-connector


Namevisier-connector JSON
Version 0.9.18 PyPI version JSON
download
home_pageNone
SummaryVisier Python Connector
upload_time2024-05-09 16:45:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
keywords visier data query connector api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![linting](https://github.com/visier/connector-python/actions/workflows/pylint.yml/badge.svg) ![pypi publishing](https://github.com/visier/connector-python/actions/workflows/publish-to-test-pypi.yml/badge.svg)
# Visier Python Connector
The Visier Python Connector allows Python developers to query against the Visier platform in Visier's SQL-like syntax.

## Prerequisites
This connector acts as a bridge between your Python application and Visier's cloud-hosted service infrastructure. To successfully connect to your Visier data, you need:
* The URL domain name prefix. For example: `https://{vanity-name}.api.visier.io`.
* An API key issued by Visier.
* One of:
    * A registered OAuth client application in your Visier tenant.
    * A Visier username and password with API access capabilities.

## Authentication Environment
As of version `0.9.8`, the Visier Python Connector supports two authentication methods:
* **OAuth 2.0**: A three-legged authentication flow that authenticates through the authorization server. In OAuth 2.0 protocol, no user credentials are provided directly to Visier. We recommend using the OAuth 2.0 authentication method.
* **Basic authentication**: A traditional authentication flow that authenticates through a Visier username and password.

To avoid passing authentication credentials in with command-line arguments, Visier recommends that basic authentication credentials, such as username and password, are passed in through environment variables. You can use the `make_auth()` function to create the appropriate authentication configuration object from `VISIER_`-prefixed environment variables, as described below.

### OAuth 2.0
The following list defines the OAuth 2.0 authentication parameters. These are also the environment and `dotenv` variables the `make_auth()` utility function will use when instantiating an authentication object.
* `VISIER_HOST`: The fully qualified domain name and protocol to access your Visier tenant and initiate the OAuth 2.0 authentication process.
* `VISIER_APIKEY`: The API key granted by Visier.
* `VISIER_CLIENT_ID`: The identifier of the registered client application.
* `VISIER_CLIENT_SECRET`: The generated secret of the registered client application. This is required for customer-registered applications.
* `VISIER_REDIRECT_URI`: The URI the `authorize` call will redirect to upon a successful authorization code generation. By default, this is `http://localhost:5000/oauth2/callback` but the URI must match the `redirect_uri` in the client application registration exactly. If the client application URI is different, it is essential that that exact value is provided to the Python connector.
* `VISIER_TARGET_TENANT_ID`: The tenant code of the target tenant. This is only applicable in partner configurations.

The following example illustrates an authentication environment. Let's say you're using a Linux-like system with an X-display available. First, create a file named `.env` and then populate the file as shown next, substituting the example values with actual values as appropriate.
```sh
export VISIER_HOST=https://customer-specific.api.visier.io
export VISIER_CLIENT_ID=client-id
export VISIER_APIKEY=the-api-key-issued-by-visier
export VISIER_REDIRECT_URI=
# export VISIER_REDIRECT_URI=http://localhost:5000/oauth2/callback
export VISIER_TARGET_TENANT_ID=
export VISIER_USERNAME=
export VISIER_PASSWORD=

echo -n "Enter the client secret for client with id $VISIER_CLIENT_ID: "
read -s secret
export VISIER_CLIENT_SECRET=$secret
```

**Note**: You may provide a valid username and password combination with the variables above. If a username and password are provided along with the client ID and secret, the connector will use the password grant type instead of the authorization code grant type. We do not recommend the password grant type in a production environment.

Next, source the file below in and then the environment is ready to use the connector with OAuth 2.0 authentication.
```sh
$ source .env
```

Because the connector supports [python-dotenv](https://pypi.org/project/python-dotenv/) , some users may prefer to define assignments directly in `.env` instead of sourcing it into the OS environment. In the following snippet, the connector uses credentials obtained with dotenv.
```python
from dotenv import dotenv_values
from visier.connector import VisierSession, make_auth
from visier.api import ModelApiClient

env_creds = dotenv_values()
auth = make_auth(env_values=env_creds)

with VisierSession(auth) as s:
    ...
```
#### Callback URI
The OAuth 2.0 authentication flow requires that the authorizing server can call back to the initiating client with an authorization code. In OAuth mode, the connector starts a transient web server that listens for an authorization code on http://localhost:5000/oauth2/callback. You can modify the URL by setting a different value for `VISIER_REDIRECT_URI`. The `VISIER_REDIRECT_URI` value must exactly match the URI value in your Visier OAuth 2.0 client registration and must respect Visier's callback URI rules, such as a limited set of permissible subnets.

### Basic Authentication
The Visier Python Connector doesn't directly interact with the environment variables. The following list defines the basic authentication parameters. The basic authentication parameters are also the environment variables that the `make_auth()` utility function uses.
* `VISIER_HOST`: The fully qualified domain name and protocol to access your Visier tenant.
* `VISIER_USERNAME`: The Visier user that has sufficient API capabilities.
* `VISIER_PASSWORD`: The password of that user.
* `VISIER_APIKEY`: The API key granted by Visier.
* `VISIER_VANITY`: The vanity name of the Visier tenant.
* `VISIER_TARGET_TENANT_ID`: The tenant code of the target tenant. This is only applicable in partner configurations.

The following example illustrates an authentication environment. The example is suitable in a non-production environment.

Let's say you're using a Linux-like system. First, create a file named `.env` and then populate the file as shown next, substituting the example values with actual values as appropriate.
```sh
echo -n "Enter the password for the Visier API User: "
read -s vpwd
export VISIER_VANITY=customer-specific
export VISIER_HOST=https://$VISIER_VANITY.api.visier.io
export VISIER_USERNAME=apiuser@example.com
export VISIER_PASSWORD=$vpwd
export VISIER_TARGET_TENANT_ID=tenant-code
export VISIER_APIKEY=the-api-key-issued-by-visier
export VISIER_CLIENT_ID=
```

Next, source this environment in and provide the password when prompted.
```sh
$ source .env
```

## Jupyter Notebooks
Jupyter notebooks and lab are well-suited to run Visier connector code. However, some users may not find OS-level variables ideal. As of version `0.9.9`, the Visier Python connector supports [dotenv](https://pypi.org/project/python-dotenv/) to facilitate a more dynamic switching of Visier authentication parameters. If the file is called `.env`, the Python package `dotenv` attempts to load the file. If the file has a different name, you must provide that file name when loading the environment with `dotenv`.

### Jupyter Basic Authentication Example
Basic authentication is the most practical means of authenticating against Visier for Jupyter notebooks.

Create an environment file to store the authentication parameters.

Example environment file:
```
VISIER_VANITY=customer-specific
VISIER_HOST=https://customer-specific.api.visier.io
VISIER_APIKEY=the-api-key-issued-by-visier
VISIER_USERNAME=apiuser@example.com
VISIER_PASSWORD=password-or-variable-reference
```

Create a basic authentication object as described in the following snippet:
```python
from dotenv import dotenv_values
from visier.connector import VisierSession, make_auth
from visier.api import QueryApiClient

env_creds = dotenv_values()
auth = make_auth(env_values=env_creds)

with VisierSession(auth) as s:
    query_client = QueryApiClient(s)
    ...
```

### Jupyter OAuth 2.0 Example
OAuth authentication to Visier in Jupyter notebooks is only supported when the Jupyter server runs on your local computer, bound to `localhost`. We only recommend using OAuth in Jupyter notebooks against Visier for test and development uses.

To authenticate with OAuth, you must first register an OAuth 2.0 client in Visier. Visier administrators can register OAuth clients.

After the OAuth client is registered in Visier, create an environment file to store the authentication parameters.

Example environment file:
```
VISIER_HOST=https://customer-specific.api.visier.io
VISIER_CLIENT_ID=client-id-from-registration
VISIER_APIKEY=the-api-key-issued-by-visier
```

Create an OAuth authentication object, as described next.
```python
from dotenv import dotenv_values
from visier.connector import VisierSession, make_auth
from visier.api import QueryApiClient

env_creds = dotenv_values()
auth = make_auth(env_values=env_creds)

with VisierSession(auth) as s:
    query_client = QueryApiClient(s)
    ...
```

## Connector Separation
As of version `0.9.5`, the Python connector separates API calls from the `VisierSession` object. As a result of this change, query execution methods on the `VisierSession` are deprecated and will be removed in a future release.

As of version `0.9.5`, you can invoke Visier public APIs through the Visier Python connector by instantiating the appropriate API client and calling the methods defined on the client object. The following example invokes the `analytic-objects` Data Model endpoint to retrieve metadata for two analytic objects: `Requisition` and `Employee_Exit`.
```python
    with VisierSession(auth) as session:
        model_client = ModelApiClient(session)

        objs = model_client.get_analytic_objects(["Requisition", "Employee_Exit"])
        print(objs.text)
```
### Error Handling
By default, a failed API call returns `None` and information about the error is available on the client object. Using the example above, if the call failed, the value of `objs` is `None` (no value). To investigate why the call failed, you can call `model_client.last_error()` to find the issue.

It's possible to force the API client to instead raise a `QueryExecutionException`. To do so, instantiate the API client with the parameter value `raise_on_error=True`. Using the example above, the `model_client` instantiation would appear as `model_client = ModelApiClient(session, raise_on_error=True)`.

# Examples
## Data Query API
The Query API client makes calls to Visier's Data Query API. The Data Query API examples use [Pandas](https://pandas.pydata.org/) to illustrate common data engineering and data science workflows using Visier data.

**Note**: The `examples` in this repository are not included in the `visier-connector` package. To use the `examples`, copy them into a sample application or run the example queries with a test script in this repository as shown in the samples below.
 
Generally, Visier Query API queries are one of:
* **List query**: List queries provide a detailed, non-aggregated view of underlying analytic objects in a tabular format. Each table attribute represents a column in the result set. List queries are also referred to as `detail` or `drill through` queries.
* **Aggregate query**: Aggregate queries aggregate metric values. The API aggregates the query's defined axes and then produces multi-dimensional cell sets. To get a flat response rather than a multi-dimensional response, you can provide an `Accept` header whose first value is either `application/jsonlines` or `text/csv`. You must always include `application/json` after the flat format to successfully get error responses.

If you'd prefer not to make JSON-based queries, Visier offers a SQL-like alternative that allows you to make queries in a language close to SQL. This is preferable for users who prefer the more compact and intuitive aspects of SQL. You can define both aggregate and list queries in Visier's SQL-like dialect.

In this repository, example queries are provided in individual files for your convenience. However, SQL-like is formed with simple strings and can be provided to the call itself rather than in files.

To reduce duplication, ensure that you precede each sample with the necessary `import` statements and authentication credential definition, as shown next. 

**Note**: The use of pandas here is for demonstration purposes. The Visier Python Connector does not depend on pandas.
```python
import os
from visier.connector import VisierSession, make_auth
from visier.api import QueryApiClient
from examples import load_json, load_str
import pandas as pd

auth = make_auth()
```

### List Query
List data is granular, non-aggregated data from Visier objects like the `Employee` subject or the `Compensation_Payout` event. In this example, we define a snippet to get `Employee.Pay_Level` that you can add to a third-party resource that loads detailed data; for example, a Jupyter Notebook.
```python
with VisierSession(auth) as s:
    client = QueryApiClient(s)
    # List query from JSON query definition
    list_query = load_json("detail/employee-pay_level.json")
    list_result = client.list(list_query)
    df_list = pd.DataFrame.from_records(data=list_result.rows(), columns=list_result.header)

    # ...
    print(df_list.head)
```

### Snapshot Query
Snapshot queries retrieve a collection of `list` query-style snapshots taken at the defined intervals. A `snapshot` query's structure and result granularity is similar to a `list` query. You can think of a `snapshot` query as a sequence of `list` queries executed at specific times.

You can augment the `snapshot` result with the `effectiveDateProperty` property to include the time of each snapshot. For more information about using the `effectiveDateProperty` property, see the referenced sample JSON [query definition](/examples/snapshot/employee-info.json).
```python
with VisierSession(auth) as s:
    client = QueryApiClient(s)
    # Snapshot query from JSON query definition
    snapshot_query = load_json("snapshot/employee-info.json")
    snapshot_result = client.snapshot(snapshot_query)
    df_snapshot = pd.DataFrame.from_records(data=snapshot_result.rows(), columns=snapshot_result.header)

    # ...
    print(df_snapshot.head)
```

### Aggregate Query
Aggregate queries execute queries using Visier metrics. A metric is a business question or concern that is quantifiable as a number. Visier metrics range from simple metrics like `employeeCount` to more complex metrics like `hrRecruitingBudgetedLaborCostPerFTE`. In this example, we define a query to aggregate `applicantCount` by `Application_Source` and `Applicant_Stage`.

With a `VisierSession` available, an aggregate query is executed functionally identically.
```python
with VisierSession(auth) as s:
    client = QueryApiClient(s)
    # Aggregate query from JSON query definition
    aggregate_query = load_json("aggregate/applicants-source.json")
    aggregate_result = client.aggregate(aggregate_query)
    df_aggregate = pd.DataFrame.from_records(data=aggregate_result.rows(), columns=aggregate_result.header)

    # Now that the data is in a Pandas Data Frame, do something with it, or just...
    print(df_aggregate.head)
```

### SQL-Like Query
You can write SQL-like queries to define both list and aggregate queries.

#### SQL-Like List Query
In this example, we define a snippet to get the `EmployeeID`, `Union_Status`, `Direct_Manager.Gender`, `Direct_Manager.Vaccination_Status` where `isFemale` = `TRUE` and `isHighPerformer` = `TRUE` between January 1, 2020 and December 31, 2021.
```python
with VisierSession(auth) as s:
    client = QueryApiClient(s)
    # SQL-like detail query
    sql_detail_query = load_str("sql-like/detail/employee-demo.sql")
    list_result = client.sqllike(sql_detail_query)
    df_list = pd.DataFrame.from_records(data=list_result.rows(), columns=list_result.header)

    # ...
    print(df_list.head)
```

#### SQL-Like Aggregate Query
In this example, we define a snippet to aggregate `employeeCount` by `Location_0`, `Gender`, `Union_Status`, and `Location_1` for 4 periods of 3 months each starting from April 1, 2020. In aggregate SQL-like queries, you can use `options` to eliminate cells with zero and null values. This reduces the size of the overall result set to only include rows whose metric value is more than 0.
```python
with VisierSession(auth) as s:
    client = QueryApiClient(s)
    # SQL-like aggregate query
    sql_aggregate_query = load_str("sql-like/aggregate/employee-count.sql")
    sparse_options = load_json("sql-like/options/sparse.json")
    aggregate_result = client.sqllike(sql_aggregate_query, sparse_options)
    df_aggregate = pd.DataFrame.from_records(data=aggregate_result.rows(), columns=aggregate_result.header)

    # ...
    print(df_aggregate.head)
```

## Data Model API
The Model API client makes calls to Visier's Data Model API.

To run the example below, add the following import statement to your program.
```python
from visier.api import ModelApiClient
```

In this example, we query for the metadata of selection concepts on the `Requisition` analytic object: `isRequisitionbyOtherIncomingReasons` and `isActiveRequisition`.
```python
    with VisierSession(auth) as session:
        model_client = ModelApiClient(session)

        concepts = model_client.get_selection_concepts("Requisition", ["isRequisitionbyOtherIncomingReasons", "isActiveRequisition"])
        print(concepts)
```

## Direct Data Intake API
The Direct Intake API allows users to load data whose structure already matches the target analytic object. To instantiate the Direct Data Intake API, follow the same pattern as the Data Query API and Data Model API.
First, import the appropriate API client: `from visier.api import DirectIntakeApiClient`

**Note**:
- The Direct Data Intake API requires that your source data is  cleansed, deduplicated, and transformed before sending the data to Visier. If any of these criteria are not met, the Direct Data Intake API is not suitable for loading data. You may instead send data to Visier through alternative methods, such as SFTP or data connectors.
- The Direct Data Intake API call sequence follows a transactional pattern. You first start a transaction, then make the required file uploads to the transaction, and finally commit the  transaction. If a transaction must be aborted, you can instead roll back the transaction instead of committing it.

:warning: The API caller must have sufficient capabilities in Visier to successfully call the Direct Data Intake API.

### Data Load Schema
To understand the required structure to load data into target objects, use the `schemas` endpoint. The `schemas` endpoint returns the data load schema, or staging schema, of a specified target object.
```python
schema = intake_client.get_object_schema("Employee_Exit")
```
The data load schema is distinct from the analytic schema retrieved through the Data Model API. The analytic schema defines an object's attributes, such as its display name and associated dimensions. The data load schema defines an object's mandatory and optional data columns, data type, and other schema details.

### File Upload
In this example, we load data for `Employee` and `Employee_Exit`.
```python
    with VisierSession(auth) as session:
        intake_client = DirectIntakeApiClient(session, raise_on_error=True)

        try:
            response = intake_client.start_transaction()
            tx_id = response.json()["transactionId"]
            print(f"Transaction ID: {tx_id}")

            response = intake_client.upload_file(tx_id, "Employee", "/tmp/data/employee-data.zip")
            print(response)

            response = intake_client.upload_file(tx_id, "Employee_Exit", "/tmp/data/exits.csv")
            print(response)
            
            response = intake_client.commit_transaction(tx_id)
            print(response)
        except:
            print(f"Intake failed. Rolling back {tx_id}")
            intake_client.rollback_transaction(tx_id)
```

### Other Uses
In addition to querying data, this connector provides a lower level, generic function for executing other public Visier APIs. The following example illustrates how this connector can determine all the plans defined on a plan model.
```python
def get_location_levels(context: SessionContext) -> Response:
    path = "/v1/data/model/plan-models/WorkforcePlanModel/plans"
    return context.session().get(url=context.mk_url(path))

with VisierSession(auth) as s:
    levels = s.execute(get_location_levels)
    print(levels.json())
```

## Data Version Export API
The Data Version (DV) Export API allows users to export data version information, such as tables, columns, and file information, in CSV format.

To use the connector, add the following statement to your program.
```python
from visier.api import DVExportApiClient
```

### Schedule a Data Version Export Job
Use the client to schedule a DV export job, poll the job's status until completion to retrieve the export ID, then get the 
export information.
```python
with VisierSession(auth) as s:
    dv_export_client = DVExportApiClient(s)

    if is_initial_export:
        schedule_response = dv_export_client.schedule_initial_data_version_export_job(12345)
    else:
        schedule_response = dv_export_client.schedule_delta_data_version_export_job(12345, 67890)

    job_id = schedule_response.json()['jobUuid']
    print(f"DV Export job scheduled with job_id={job_id}")

    while True:
        print(f"Checking for completion of job_id={job_id}")
        poll_response = dv_export_client.get_data_version_export_job_status(job_id)

        poll_response_json = poll_response.json()
        if poll_response_json['completed']:
            export_id = poll_response_json['exportUuid']
            print(f"job_id={job_id} complete with export_id={export_id}")
            break
        else:
            poll_interval = 5
            print(f"Checking job_id={job_id} status in {poll_interval} seconds")
            time.sleep(poll_interval)

    export_metadata_response = dv_export_client.get_data_version_export_metadata(export_id)
    print(f"Retrieved export metadata: {export_metadata_response.json()}")
```

### Download a File From a Data Version Export
After the DV export job completes, you can use the returned export ID to retrieve information about the tables 
in the data version and data files for the tables. Then, use the file ID to download a specific table from the data version export. The file contains DV records for
a particular table's columns; for example, the columns in the Employee table.
#### Decompress File During Download
```python
    with dv_export_client.get_export_file(export_id, file_id) as r:
        with open(full_file_path, 'wb') as f:
            for chunk in r.iter_content(chunk_size=None):
                if chunk:
                    f.write(chunk)
```

#### Download as Compressed File (Optional)
To avoid decompressing the file during download, set `stream=True`. 
```python
    with dv_export_client.get_export_file(export_id, file_id, stream=True) as r:
        with open(full_file_path, 'wb') as f:
            for chunk in r.raw.stream(1024, decode_content=False):
                if chunk:
                    f.write(chunk)
```

### Retrieve a List of All Data Versions
Use this method to get the available data versions that you can export.
```python
    dv_response = dv_export_client.get_data_versions_available_for_export()
    print(f"Retrieved available data versions:  {dv_response.json()}")
```

### Retrieve the Details of All Data Version Exports
Use this method to get the export information for all completed export jobs.
```python
    exports_response = dv_export_client.get_available_data_version_exports()
    print(f"Full metadata for all DV exports retrieved: {exports_response.json()}")
```

### More Examples
For a script example that shows how the Data Version Export API client can export a data version into a database, see 
[github.com/visier/api-samples](https://github.com/visier/api-samples).

## Installation
Add `visier-connector` as a dependency to your module or install `pip install -U visier-connector` directly.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "visier-connector",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "visier, data, query, connector, api",
    "author": null,
    "author_email": "Visier Research & Development <info@visier.com>",
    "download_url": "https://files.pythonhosted.org/packages/3c/c7/044bfc62a4df43fa758f10e3af705833aaefb1f92c1ac762753dad442b4c/visier_connector-0.9.18.tar.gz",
    "platform": null,
    "description": "![linting](https://github.com/visier/connector-python/actions/workflows/pylint.yml/badge.svg) ![pypi publishing](https://github.com/visier/connector-python/actions/workflows/publish-to-test-pypi.yml/badge.svg)\n# Visier Python Connector\nThe Visier Python Connector allows Python developers to query against the Visier platform in Visier's SQL-like syntax.\n\n## Prerequisites\nThis connector acts as a bridge between your Python application and Visier's cloud-hosted service infrastructure. To successfully connect to your Visier data, you need:\n* The URL domain name prefix. For example: `https://{vanity-name}.api.visier.io`.\n* An API key issued by Visier.\n* One of:\n    * A registered OAuth client application in your Visier tenant.\n    * A Visier username and password with API access capabilities.\n\n## Authentication Environment\nAs of version `0.9.8`, the Visier Python Connector supports two authentication methods:\n* **OAuth 2.0**: A three-legged authentication flow that authenticates through the authorization server. In OAuth 2.0 protocol, no user credentials are provided directly to Visier. We recommend using the OAuth 2.0 authentication method.\n* **Basic authentication**: A traditional authentication flow that authenticates through a Visier username and password.\n\nTo avoid passing authentication credentials in with command-line arguments, Visier recommends that basic authentication credentials, such as username and password, are passed in through environment variables. You can use the `make_auth()` function to create the appropriate authentication configuration object from `VISIER_`-prefixed environment variables, as described below.\n\n### OAuth 2.0\nThe following list defines the OAuth 2.0 authentication parameters. These are also the environment and `dotenv` variables the `make_auth()` utility function will use when instantiating an authentication object.\n* `VISIER_HOST`: The fully qualified domain name and protocol to access your Visier tenant and initiate the OAuth 2.0 authentication process.\n* `VISIER_APIKEY`: The API key granted by Visier.\n* `VISIER_CLIENT_ID`: The identifier of the registered client application.\n* `VISIER_CLIENT_SECRET`: The generated secret of the registered client application. This is required for customer-registered applications.\n* `VISIER_REDIRECT_URI`: The URI the `authorize` call will redirect to upon a successful authorization code generation. By default, this is `http://localhost:5000/oauth2/callback` but the URI must match the `redirect_uri` in the client application registration exactly. If the client application URI is different, it is essential that that exact value is provided to the Python connector.\n* `VISIER_TARGET_TENANT_ID`: The tenant code of the target tenant. This is only applicable in partner configurations.\n\nThe following example illustrates an authentication environment. Let's say you're using a Linux-like system with an X-display available. First, create a file named `.env` and then populate the file as shown next, substituting the example values with actual values as appropriate.\n```sh\nexport VISIER_HOST=https://customer-specific.api.visier.io\nexport VISIER_CLIENT_ID=client-id\nexport VISIER_APIKEY=the-api-key-issued-by-visier\nexport VISIER_REDIRECT_URI=\n# export VISIER_REDIRECT_URI=http://localhost:5000/oauth2/callback\nexport VISIER_TARGET_TENANT_ID=\nexport VISIER_USERNAME=\nexport VISIER_PASSWORD=\n\necho -n \"Enter the client secret for client with id $VISIER_CLIENT_ID: \"\nread -s secret\nexport VISIER_CLIENT_SECRET=$secret\n```\n\n**Note**: You may provide a valid username and password combination with the variables above. If a username and password are provided along with the client ID and secret, the connector will use the password grant type instead of the authorization code grant type. We do not recommend the password grant type in a production environment.\n\nNext, source the file below in and then the environment is ready to use the connector with OAuth 2.0 authentication.\n```sh\n$ source .env\n```\n\nBecause the connector supports [python-dotenv](https://pypi.org/project/python-dotenv/) , some users may prefer to define assignments directly in `.env` instead of sourcing it into the OS environment. In the following snippet, the connector uses credentials obtained with dotenv.\n```python\nfrom dotenv import dotenv_values\nfrom visier.connector import VisierSession, make_auth\nfrom visier.api import ModelApiClient\n\nenv_creds = dotenv_values()\nauth = make_auth(env_values=env_creds)\n\nwith VisierSession(auth) as s:\n    ...\n```\n#### Callback URI\nThe OAuth 2.0 authentication flow requires that the authorizing server can call back to the initiating client with an authorization code. In OAuth mode, the connector starts a transient web server that listens for an authorization code on http://localhost:5000/oauth2/callback. You can modify the URL by setting a different value for `VISIER_REDIRECT_URI`. The `VISIER_REDIRECT_URI` value must exactly match the URI value in your Visier OAuth 2.0 client registration and must respect Visier's callback URI rules, such as a limited set of permissible subnets.\n\n### Basic Authentication\nThe Visier Python Connector doesn't directly interact with the environment variables. The following list defines the basic authentication parameters. The basic authentication parameters are also the environment variables that the `make_auth()` utility function uses.\n* `VISIER_HOST`: The fully qualified domain name and protocol to access your Visier tenant.\n* `VISIER_USERNAME`: The Visier user that has sufficient API capabilities.\n* `VISIER_PASSWORD`: The password of that user.\n* `VISIER_APIKEY`: The API key granted by Visier.\n* `VISIER_VANITY`: The vanity name of the Visier tenant.\n* `VISIER_TARGET_TENANT_ID`: The tenant code of the target tenant. This is only applicable in partner configurations.\n\nThe following example illustrates an authentication environment. The example is suitable in a non-production environment.\n\nLet's say you're using a Linux-like system. First, create a file named `.env` and then populate the file as shown next, substituting the example values with actual values as appropriate.\n```sh\necho -n \"Enter the password for the Visier API User: \"\nread -s vpwd\nexport VISIER_VANITY=customer-specific\nexport VISIER_HOST=https://$VISIER_VANITY.api.visier.io\nexport VISIER_USERNAME=apiuser@example.com\nexport VISIER_PASSWORD=$vpwd\nexport VISIER_TARGET_TENANT_ID=tenant-code\nexport VISIER_APIKEY=the-api-key-issued-by-visier\nexport VISIER_CLIENT_ID=\n```\n\nNext, source this environment in and provide the password when prompted.\n```sh\n$ source .env\n```\n\n## Jupyter Notebooks\nJupyter notebooks and lab are well-suited to run Visier connector code. However, some users may not find OS-level variables ideal. As of version `0.9.9`, the Visier Python connector supports [dotenv](https://pypi.org/project/python-dotenv/) to facilitate a more dynamic switching of Visier authentication parameters. If the file is called `.env`, the Python package `dotenv` attempts to load the file. If the file has a different name, you must provide that file name when loading the environment with `dotenv`.\n\n### Jupyter Basic Authentication Example\nBasic authentication is the most practical means of authenticating against Visier for Jupyter notebooks.\n\nCreate an environment file to store the authentication parameters.\n\nExample environment file:\n```\nVISIER_VANITY=customer-specific\nVISIER_HOST=https://customer-specific.api.visier.io\nVISIER_APIKEY=the-api-key-issued-by-visier\nVISIER_USERNAME=apiuser@example.com\nVISIER_PASSWORD=password-or-variable-reference\n```\n\nCreate a basic authentication object as described in the following snippet:\n```python\nfrom dotenv import dotenv_values\nfrom visier.connector import VisierSession, make_auth\nfrom visier.api import QueryApiClient\n\nenv_creds = dotenv_values()\nauth = make_auth(env_values=env_creds)\n\nwith VisierSession(auth) as s:\n    query_client = QueryApiClient(s)\n    ...\n```\n\n### Jupyter OAuth 2.0 Example\nOAuth authentication to Visier in Jupyter notebooks is only supported when the Jupyter server runs on your local computer, bound to `localhost`. We only recommend using OAuth in Jupyter notebooks against Visier for test and development uses.\n\nTo authenticate with OAuth, you must first register an OAuth 2.0 client in Visier. Visier administrators can register OAuth clients.\n\nAfter the OAuth client is registered in Visier, create an environment file to store the authentication parameters.\n\nExample environment file:\n```\nVISIER_HOST=https://customer-specific.api.visier.io\nVISIER_CLIENT_ID=client-id-from-registration\nVISIER_APIKEY=the-api-key-issued-by-visier\n```\n\nCreate an OAuth authentication object, as described next.\n```python\nfrom dotenv import dotenv_values\nfrom visier.connector import VisierSession, make_auth\nfrom visier.api import QueryApiClient\n\nenv_creds = dotenv_values()\nauth = make_auth(env_values=env_creds)\n\nwith VisierSession(auth) as s:\n    query_client = QueryApiClient(s)\n    ...\n```\n\n## Connector Separation\nAs of version `0.9.5`, the Python connector separates API calls from the `VisierSession` object. As a result of this change, query execution methods on the `VisierSession` are deprecated and will be removed in a future release.\n\nAs of version `0.9.5`, you can invoke Visier public APIs through the Visier Python connector by instantiating the appropriate API client and calling the methods defined on the client object. The following example invokes the `analytic-objects` Data Model endpoint to retrieve metadata for two analytic objects: `Requisition` and `Employee_Exit`.\n```python\n    with VisierSession(auth) as session:\n        model_client = ModelApiClient(session)\n\n        objs = model_client.get_analytic_objects([\"Requisition\", \"Employee_Exit\"])\n        print(objs.text)\n```\n### Error Handling\nBy default, a failed API call returns `None` and information about the error is available on the client object. Using the example above, if the call failed, the value of `objs` is `None` (no value). To investigate why the call failed, you can call `model_client.last_error()` to find the issue.\n\nIt's possible to force the API client to instead raise a `QueryExecutionException`. To do so, instantiate the API client with the parameter value `raise_on_error=True`. Using the example above, the `model_client` instantiation would appear as `model_client = ModelApiClient(session, raise_on_error=True)`.\n\n# Examples\n## Data Query API\nThe Query API client makes calls to Visier's Data Query API. The Data Query API examples use [Pandas](https://pandas.pydata.org/) to illustrate common data engineering and data science workflows using Visier data.\n\n**Note**: The `examples` in this repository are not included in the `visier-connector` package. To use the `examples`, copy them into a sample application or run the example queries with a test script in this repository as shown in the samples below.\n \nGenerally, Visier Query API queries are one of:\n* **List query**: List queries provide a detailed, non-aggregated view of underlying analytic objects in a tabular format. Each table attribute represents a column in the result set. List queries are also referred to as `detail` or `drill through` queries.\n* **Aggregate query**: Aggregate queries aggregate metric values. The API aggregates the query's defined axes and then produces multi-dimensional cell sets. To get a flat response rather than a multi-dimensional response, you can provide an `Accept` header whose first value is either `application/jsonlines` or `text/csv`. You must always include `application/json` after the flat format to successfully get error responses.\n\nIf you'd prefer not to make JSON-based queries, Visier offers a SQL-like alternative that allows you to make queries in a language close to SQL. This is preferable for users who prefer the more compact and intuitive aspects of SQL. You can define both aggregate and list queries in Visier's SQL-like dialect.\n\nIn this repository, example queries are provided in individual files for your convenience. However, SQL-like is formed with simple strings and can be provided to the call itself rather than in files.\n\nTo reduce duplication, ensure that you precede each sample with the necessary `import` statements and authentication credential definition, as shown next. \n\n**Note**: The use of pandas here is for demonstration purposes. The Visier Python Connector does not depend on pandas.\n```python\nimport os\nfrom visier.connector import VisierSession, make_auth\nfrom visier.api import QueryApiClient\nfrom examples import load_json, load_str\nimport pandas as pd\n\nauth = make_auth()\n```\n\n### List Query\nList data is granular, non-aggregated data from Visier objects like the `Employee` subject or the `Compensation_Payout` event. In this example, we define a snippet to get `Employee.Pay_Level` that you can add to a third-party resource that loads detailed data; for example, a Jupyter Notebook.\n```python\nwith VisierSession(auth) as s:\n    client = QueryApiClient(s)\n    # List query from JSON query definition\n    list_query = load_json(\"detail/employee-pay_level.json\")\n    list_result = client.list(list_query)\n    df_list = pd.DataFrame.from_records(data=list_result.rows(), columns=list_result.header)\n\n    # ...\n    print(df_list.head)\n```\n\n### Snapshot Query\nSnapshot queries retrieve a collection of `list` query-style snapshots taken at the defined intervals. A `snapshot` query's structure and result granularity is similar to a `list` query. You can think of a `snapshot` query as a sequence of `list` queries executed at specific times.\n\nYou can augment the `snapshot` result with the `effectiveDateProperty` property to include the time of each snapshot. For more information about using the `effectiveDateProperty` property, see the referenced sample JSON [query definition](/examples/snapshot/employee-info.json).\n```python\nwith VisierSession(auth) as s:\n    client = QueryApiClient(s)\n    # Snapshot query from JSON query definition\n    snapshot_query = load_json(\"snapshot/employee-info.json\")\n    snapshot_result = client.snapshot(snapshot_query)\n    df_snapshot = pd.DataFrame.from_records(data=snapshot_result.rows(), columns=snapshot_result.header)\n\n    # ...\n    print(df_snapshot.head)\n```\n\n### Aggregate Query\nAggregate queries execute queries using Visier metrics. A metric is a business question or concern that is quantifiable as a number. Visier metrics range from simple metrics like `employeeCount` to more complex metrics like `hrRecruitingBudgetedLaborCostPerFTE`. In this example, we define a query to aggregate `applicantCount` by `Application_Source` and `Applicant_Stage`.\n\nWith a `VisierSession` available, an aggregate query is executed functionally identically.\n```python\nwith VisierSession(auth) as s:\n    client = QueryApiClient(s)\n    # Aggregate query from JSON query definition\n    aggregate_query = load_json(\"aggregate/applicants-source.json\")\n    aggregate_result = client.aggregate(aggregate_query)\n    df_aggregate = pd.DataFrame.from_records(data=aggregate_result.rows(), columns=aggregate_result.header)\n\n    # Now that the data is in a Pandas Data Frame, do something with it, or just...\n    print(df_aggregate.head)\n```\n\n### SQL-Like Query\nYou can write SQL-like queries to define both list and aggregate queries.\n\n#### SQL-Like List Query\nIn this example, we define a snippet to get the `EmployeeID`, `Union_Status`, `Direct_Manager.Gender`, `Direct_Manager.Vaccination_Status` where `isFemale` = `TRUE` and `isHighPerformer` = `TRUE` between January 1, 2020 and December 31, 2021.\n```python\nwith VisierSession(auth) as s:\n    client = QueryApiClient(s)\n    # SQL-like detail query\n    sql_detail_query = load_str(\"sql-like/detail/employee-demo.sql\")\n    list_result = client.sqllike(sql_detail_query)\n    df_list = pd.DataFrame.from_records(data=list_result.rows(), columns=list_result.header)\n\n    # ...\n    print(df_list.head)\n```\n\n#### SQL-Like Aggregate Query\nIn this example, we define a snippet to aggregate `employeeCount` by `Location_0`, `Gender`, `Union_Status`, and `Location_1` for 4 periods of 3 months each starting from April 1, 2020. In aggregate SQL-like queries, you can use `options` to eliminate cells with zero and null values. This reduces the size of the overall result set to only include rows whose metric value is more than 0.\n```python\nwith VisierSession(auth) as s:\n    client = QueryApiClient(s)\n    # SQL-like aggregate query\n    sql_aggregate_query = load_str(\"sql-like/aggregate/employee-count.sql\")\n    sparse_options = load_json(\"sql-like/options/sparse.json\")\n    aggregate_result = client.sqllike(sql_aggregate_query, sparse_options)\n    df_aggregate = pd.DataFrame.from_records(data=aggregate_result.rows(), columns=aggregate_result.header)\n\n    # ...\n    print(df_aggregate.head)\n```\n\n## Data Model API\nThe Model API client makes calls to Visier's Data Model API.\n\nTo run the example below, add the following import statement to your program.\n```python\nfrom visier.api import ModelApiClient\n```\n\nIn this example, we query for the metadata of selection concepts on the `Requisition` analytic object: `isRequisitionbyOtherIncomingReasons` and `isActiveRequisition`.\n```python\n    with VisierSession(auth) as session:\n        model_client = ModelApiClient(session)\n\n        concepts = model_client.get_selection_concepts(\"Requisition\", [\"isRequisitionbyOtherIncomingReasons\", \"isActiveRequisition\"])\n        print(concepts)\n```\n\n## Direct Data Intake API\nThe Direct Intake API allows users to load data whose structure already matches the target analytic object. To instantiate the Direct Data Intake API, follow the same pattern as the Data Query API and Data Model API.\nFirst, import the appropriate API client: `from visier.api import DirectIntakeApiClient`\n\n**Note**:\n- The Direct Data Intake API requires that your source data is  cleansed, deduplicated, and transformed before sending the data to Visier. If any of these criteria are not met, the Direct Data Intake API is not suitable for loading data. You may instead send data to Visier through alternative methods, such as SFTP or data connectors.\n- The Direct Data Intake API call sequence follows a transactional pattern. You first start a transaction, then make the required file uploads to the transaction, and finally commit the  transaction. If a transaction must be aborted, you can instead roll back the transaction instead of committing it.\n\n:warning: The API caller must have sufficient capabilities in Visier to successfully call the Direct Data Intake API.\n\n### Data Load Schema\nTo understand the required structure to load data into target objects, use the `schemas` endpoint. The `schemas` endpoint returns the data load schema, or staging schema, of a specified target object.\n```python\nschema = intake_client.get_object_schema(\"Employee_Exit\")\n```\nThe data load schema is distinct from the analytic schema retrieved through the Data Model API. The analytic schema defines an object's attributes, such as its display name and associated dimensions. The data load schema defines an object's mandatory and optional data columns, data type, and other schema details.\n\n### File Upload\nIn this example, we load data for `Employee` and `Employee_Exit`.\n```python\n    with VisierSession(auth) as session:\n        intake_client = DirectIntakeApiClient(session, raise_on_error=True)\n\n        try:\n            response = intake_client.start_transaction()\n            tx_id = response.json()[\"transactionId\"]\n            print(f\"Transaction ID: {tx_id}\")\n\n            response = intake_client.upload_file(tx_id, \"Employee\", \"/tmp/data/employee-data.zip\")\n            print(response)\n\n            response = intake_client.upload_file(tx_id, \"Employee_Exit\", \"/tmp/data/exits.csv\")\n            print(response)\n            \n            response = intake_client.commit_transaction(tx_id)\n            print(response)\n        except:\n            print(f\"Intake failed. Rolling back {tx_id}\")\n            intake_client.rollback_transaction(tx_id)\n```\n\n### Other Uses\nIn addition to querying data, this connector provides a lower level, generic function for executing other public Visier APIs. The following example illustrates how this connector can determine all the plans defined on a plan model.\n```python\ndef get_location_levels(context: SessionContext) -> Response:\n    path = \"/v1/data/model/plan-models/WorkforcePlanModel/plans\"\n    return context.session().get(url=context.mk_url(path))\n\nwith VisierSession(auth) as s:\n    levels = s.execute(get_location_levels)\n    print(levels.json())\n```\n\n## Data Version Export API\nThe Data Version (DV) Export API allows users to export data version information, such as tables, columns, and file information, in CSV format.\n\nTo use the connector, add the following statement to your program.\n```python\nfrom visier.api import DVExportApiClient\n```\n\n### Schedule a Data Version Export Job\nUse the client to schedule a DV export job, poll the job's status until completion to retrieve the export ID, then get the \nexport information.\n```python\nwith VisierSession(auth) as s:\n    dv_export_client = DVExportApiClient(s)\n\n    if is_initial_export:\n        schedule_response = dv_export_client.schedule_initial_data_version_export_job(12345)\n    else:\n        schedule_response = dv_export_client.schedule_delta_data_version_export_job(12345, 67890)\n\n    job_id = schedule_response.json()['jobUuid']\n    print(f\"DV Export job scheduled with job_id={job_id}\")\n\n    while True:\n        print(f\"Checking for completion of job_id={job_id}\")\n        poll_response = dv_export_client.get_data_version_export_job_status(job_id)\n\n        poll_response_json = poll_response.json()\n        if poll_response_json['completed']:\n            export_id = poll_response_json['exportUuid']\n            print(f\"job_id={job_id} complete with export_id={export_id}\")\n            break\n        else:\n            poll_interval = 5\n            print(f\"Checking job_id={job_id} status in {poll_interval} seconds\")\n            time.sleep(poll_interval)\n\n    export_metadata_response = dv_export_client.get_data_version_export_metadata(export_id)\n    print(f\"Retrieved export metadata: {export_metadata_response.json()}\")\n```\n\n### Download a File From a Data Version Export\nAfter the DV export job completes, you can use the returned export ID to retrieve information about the tables \nin the data version and data files for the tables. Then, use the file ID to download a specific table from the data version export. The file contains DV records for\na particular table's columns; for example, the columns in the Employee table.\n#### Decompress File During Download\n```python\n    with dv_export_client.get_export_file(export_id, file_id) as r:\n        with open(full_file_path, 'wb') as f:\n            for chunk in r.iter_content(chunk_size=None):\n                if chunk:\n                    f.write(chunk)\n```\n\n#### Download as Compressed File (Optional)\nTo avoid decompressing the file during download, set `stream=True`. \n```python\n    with dv_export_client.get_export_file(export_id, file_id, stream=True) as r:\n        with open(full_file_path, 'wb') as f:\n            for chunk in r.raw.stream(1024, decode_content=False):\n                if chunk:\n                    f.write(chunk)\n```\n\n### Retrieve a List of All Data Versions\nUse this method to get the available data versions that you can export.\n```python\n    dv_response = dv_export_client.get_data_versions_available_for_export()\n    print(f\"Retrieved available data versions:  {dv_response.json()}\")\n```\n\n### Retrieve the Details of All Data Version Exports\nUse this method to get the export information for all completed export jobs.\n```python\n    exports_response = dv_export_client.get_available_data_version_exports()\n    print(f\"Full metadata for all DV exports retrieved: {exports_response.json()}\")\n```\n\n### More Examples\nFor a script example that shows how the Data Version Export API client can export a data version into a database, see \n[github.com/visier/api-samples](https://github.com/visier/api-samples).\n\n## Installation\nAdd `visier-connector` as a dependency to your module or install `pip install -U visier-connector` directly.\n",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0, January 2004 http://www.apache.org/licenses/  TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION  1. Definitions.  \"License\" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.  \"Licensor\" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.  \"Legal Entity\" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \"control\" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.  \"You\" (or \"Your\") shall mean an individual or Legal Entity exercising permissions granted by this License.  \"Source\" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.  \"Object\" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.  \"Work\" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).  \"Derivative Works\" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.  \"Contribution\" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \"submitted\" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \"Not a Contribution.\"  \"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.  2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.  3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.  4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:  (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and  (b) You must cause any modified files to carry prominent notices stating that You changed the files; and  (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and  (d) If the Work includes a \"NOTICE\" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.  You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.  5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.  6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.  7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.  8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.  9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.  END OF TERMS AND CONDITIONS  APPENDIX: How to apply the Apache License to your work.  To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets \"[]\" replaced with your own identifying information. (Don't include the brackets!)  The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same \"printed page\" as the copyright notice for easier identification within third-party archives.  Copyright [yyyy] [name of copyright owner]  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
    "summary": "Visier Python Connector",
    "version": "0.9.18",
    "project_urls": null,
    "split_keywords": [
        "visier",
        " data",
        " query",
        " connector",
        " api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d9d7d9118c9bee981c7a6abe600ade55833514f1781fc06b24017f69ef505c0",
                "md5": "3ee930d861a92a3fb8f7e135e5070f54",
                "sha256": "7cd8c95fa0b7901b3550e877875c6966f7c3c26ce5b524018afdf0d7dba1bced"
            },
            "downloads": -1,
            "filename": "visier_connector-0.9.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3ee930d861a92a3fb8f7e135e5070f54",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 36189,
            "upload_time": "2024-05-09T16:45:01",
            "upload_time_iso_8601": "2024-05-09T16:45:01.130920Z",
            "url": "https://files.pythonhosted.org/packages/6d/9d/7d9118c9bee981c7a6abe600ade55833514f1781fc06b24017f69ef505c0/visier_connector-0.9.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3cc7044bfc62a4df43fa758f10e3af705833aaefb1f92c1ac762753dad442b4c",
                "md5": "79ed99152941c784f6354e7b6d889e24",
                "sha256": "8d93a3f0f3e164efc0f4715d5fa4d7516f68228d514ba0a3d5d310f21bfde0a0"
            },
            "downloads": -1,
            "filename": "visier_connector-0.9.18.tar.gz",
            "has_sig": false,
            "md5_digest": "79ed99152941c784f6354e7b6d889e24",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35430,
            "upload_time": "2024-05-09T16:45:11",
            "upload_time_iso_8601": "2024-05-09T16:45:11.239463Z",
            "url": "https://files.pythonhosted.org/packages/3c/c7/044bfc62a4df43fa758f10e3af705833aaefb1f92c1ac762753dad442b4c/visier_connector-0.9.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-09 16:45:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "visier-connector"
}
        
Elapsed time: 0.83388s