Skip to main content

Dfiber

Project Description

Dfiber is a Python utility that simplifies connecting to Dview's Aqua and executing SQL queries. It supports flexible authentication methods, including:

  • API Key
  • User Email/Password
  • Cookies

Dfiber automatically handles the connection setup and provides seamless query execution, ensuring efficient interaction with your data sources.

Features

  • Library for connecting with Dview
  • Flexible authentication methods
  • Executes SQL queries and returns results

Installation

To install Dfiber, use the following pip command:

pip install dfiber

Note

  • Before using Dfiber, make sure that the DFIBER_ENDPOINT environment variable is set on your system. This variable defines the connection endpoint to Dfiber's service
export DFIBER_ENDPOINT="dfiber://<host>:<port>/<catalog>/<schema>"

Usage

Dfiber Authentication Methods

  • First, import the necessary classes from the dfiber package to work with credentials and authentication methods:
from dfiber import Credentials
from dfiber import AuthMethod
  1. API Key Authentication (Preferred Way)
  • If you prefer API key-based authentication, you can generate an API key from the Dview.io profile page. Simply create your key and use it in the api_key field.
# Credentials for API key-based authentication
credentials = Credentials(
    api_key="<api_key>",  # Required for api-key-based authentication
    auth_method=AuthMethod.API_KEY  # Specify the chosen auth method
)
  1. UserEmail-Password Authentication
  • To use email-password-based authentication, you must provide both a user email and a password. This method is ideal for logging in with your personal account credentials.
# Credentials for email-password-based authentication
credentials = Credentials(
    email="<email>", # Required for email-password-based authentication
    password="<password>", # Required for email-password-based authentication
    auth_method=AuthMethod.EMAIL_PASSWORD  # Specify the chosen auth method
)
  • For cookie-based authentication, pass the cookie token that you obtained after logging in with your email and password. This cookie can be used for subsequent requests to authenticate automatically. Only the cookie is required for this method—there’s no need to provide the email or password again.
  • However, the cookie has a specific time limit and will expire after a set period. Once the cookie expires, you will need to log in again to obtain a new cookie token.
# Credentials for cookie-based authentication
credentials = Credentials(
    cookie="<cookie>",  # Required for cookie-based authentication
    auth_method=AuthMethod.COOKIE  # Specify the chosen auth method
)

Note:

Here Credentials can also be passed as a dictionary in this way:

credentials_dict = {
    "email": "<email>",
    "password": "<password>",
    "auth_method": AuthMethod.EMAIL_PASSWORD
}

Querying using Dfiber Class

  • Dfiber class allows you to easily interact with Dview's services. The primary way to use it is by passing your credentials, catalog, and an optional schema. Additionally, you can specify the Dfiber endpoint either via environment variable DFIBER_ENDPOINT or directly through the class constructor.

Dfiber Class Overview

  • catalog: This is a required parameter and must always be provided. It specifies which catalog to query against.
  • schema: This is optional in both the dfiber_endpoint string and the Dfiber class constructor. If a schema is provided in both places (environment variable and the constructor), the one passed to the class takes precedence.
  • dfiber_endpoint: This is an optional parameter that can be passed to the Dfiber. If it's not provided, Dfiber will look for the DFIBER_ENDPOINT environment variable. If both are provided, the constructor’s parameter will override the environment variable.
  • cosmos_endpoint: This is an optional parameter for the Dfiber class. If not provided, it will fallback to the value of the DVIEW_COSMOS_ENDPOINT environment variable. If both the parameter and environment variable are set, the parameter passed to the constructor will take precedence.

The Dfiber Endpoint follows the format:

DFIBER_ENDPOINT="dfiber://<host>:<port>/<catalog>/<schema>"

Here, <host>, <port>, <catalog>, and <schema> need to be replaced with appropriate values. The schema part is optional, and if omitted, Dfiber will use the schema you provide directly.

Examples

1. Using Dfiber Class with Catalog Only
  • In this case, the Dfiber class will use the DFIBER_ENDPOINT from your environment variable (if it's set) and the catalog passed to the class. If the schema is omitted in both the Dfiber endpoint and class, you can still specify it directly within your query, and Dfiber will handle the query accordingly.
from dfiber import Dfiber, AuthMethod

# Define credentials
credentials_dict = {
    "email": "<email>",
    "password": "<password>",
    "auth_method": AuthMethod.EMAIL_PASSWORD
}

# Dfiber instance with catalog only, Dfiber will pick up endpoint from the environment variable
dfiber = Dfiber(credentials=credentials_dict, catalog="<catalog>")

# Execute a query
result_df = dfiber.execute_query("<your_query>")
2. Using Custom Dfiber Endpoint and catalog override
  • If you wish to pass a custom dfiber_endpoint directly in the constructor, Dfiber will override the one set in the environment variable(DFIBER_ENDPOINT).
  • The catalog in the dfiber_endpoint can be overridden by the catalog passed into the Dfiber class.
from dfiber import Dfiber, AuthMethod, Credentials

# Define credentials
credentials = Credentials(
    cookie="<cookie>",
    auth_method=AuthMethod.COOKIE
)

# Dfiber instance with custom Dfiber endpoint, specifying catalog and schema
dfiber = Dfiber(credentials=credentials,
                catalog="<custom_catalog>",
                dfiber_endpoint="dfiber://<host>:<port>/catalog/custom_schema")

# Execute a query
result_df = dfiber.execute_query("<your_query>")
3.Override Custom Dfiber Endpoint Schema with a Custom Schema
  • If both the dfiber_endpoint and the schema are provided to the Dfiber class, the schema passed to the Dfiber class will take precedence over the one specified in the dfiber_endpoint variable or in the DFIBER_ENDPOINT environment variable.
from dfiber import Dfiber, AuthMethod

# Define credentials
credentials_dict = {
    "api_key": "<api_key>",
    "auth_method": AuthMethod.API_KEY
}

# Dfiber instance with schema provided directly
dfiber = Dfiber(credentials=credentials_dict, 
                catalog="<catalog>",
                schema="<custom_schema>",
                dfiber_endpoint="dfiber://<host>:<port>/catalog/schema")

# Execute a query
result_df = dfiber.execute_query("<your_query>")

Contributors

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for dfiber 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dfiber 0.1.2
File Size Uploaded Provenance Actions
dfiber-0.1.2.tar.gz 10.4 kB Without provenance Details for dfiber-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dfiber 0.1.2
File Interpreter ABI Platform Actions
dfiber-0.1.2-py3-none-any.whl Python 3 none any Details for dfiber-0.1.2-py3-none-any.whl

Total release size: 21.9 kB

Release files / dfiber-0.1.2.tar.gz

Download URL dfiber-0.1.2.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2e34e5e3b45efd29e12508b79dfaab1d763aabbe517beda03da7ce051ee6670c
BLAKE2b-256 checksum
How to use checksums
e2b42d66d538362c98d6aa09203c7aa1955ea6be6a78ddf1eb3bba45404d6639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.13.0 Darwin/22.2.0

Release files / dfiber-0.1.2-py3-none-any.whl

Download URL dfiber-0.1.2-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
317c953ef41d77605eaa36ee0676ffc1130b0daa1398c20d1c4e7294209444f4
BLAKE2b-256 checksum
How to use checksums
d9895bcead6b88fc77ad069ad78f94e58327b19975b96a5a4ec771e5b6244df9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.13.0 Darwin/22.2.0

Security for dfiber 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page