Skip to main content

Timbr Python connector

Project description

Timbr logo

timbr Python connector sample file

This project is a sample connecting to timbr using Python.

Dependencies

  • Python 3.7.13+ or 3.8.x or 3.9.x
  • Java 8 or Java 11

Installation

Sample usage

  • For an example of how to use the Python connector for Timbr:
  • For an example of using the Timbr Python connector with Pandas:
    • Make sure you have the pandas library installed, or you can install it by running pip install pandas
    • Create connection with params, follow this Example File
    • Create JDBC connection, follow this Example File

Create basic connection

Create connection with params

  conn = pytimbr.getConnection(
    hostname = '<TIMBR_IP/HOST>',
    port = '<TIMBR_PORT>',
    ontology = '<ONTOLOGY_NAME>',
    username = '<TIMBR_USER/token>',
    password = '<TIMBR_PASSWORD/TOKEN_VALUE>',
    enabled_ssl = '<false/true>',
    http_path = '<TIMBR_SERVER_HTTP_PATH>'
  )

  # hostname - The IP / Hostname of the Timbr server (not necessarily the hostname of the Timbr platform).
  # port - The port to connect to in the Timbr server. Timbr's default port with enabled_ssl is 443 without SSL is 11000.
  # ontology - the ontology / knowledge graph to connect to.
  # username - Use 'token' as the username when connecting using a Timbr token, otherwise its the user name.
  # password - Should be the token value if using a token as a username, otherwise its the user's password.
  # enabled_ssl - true if SSL is enabled, false if SSL is disabled.
  # http_path - Use only if your timbr server http path is not '/timbr-server'.

Create JDBC connection

  hostname = '<TIMBR_IP/HOST>'
  port = '<TIMBR_PORT>'
  ontology = '<ONTOLOGY_NAME>'
  username = '<TIMBR_USER/token>'
  password = '<TIMBR_PASSWORD/TOKEN_VALUE>'
  enabled_ssl = '<false/true>'
  http_path = '<TIMBR_SERVER_HTTP_PATH>'
  
  # hostname - The IP / Hostname of the Timbr server (not necessarily the hostname of the Timbr platform).
  # port - The port to connect to in the Timbr server. Timbr's default port with enabled_ssl is 443 without SSL is 11000.
  # ontology - the ontology / knowledge graph to connect to.
  # username - Use 'token' as the username when connecting using a Timbr token, otherwise its the user name.
  # password - Should be the token value if using a token as a username, otherwise its the user's password.
  # enabled_ssl - true if SSL is enabled, false if SSL is disabled.
  # http_path - Use only if your timbr server http path is not '/timbr-server'.
  
  # Create new JDBC connection
  conn = pytimbr.getJdbcConnection(
    f"jdbc:hive2://{hostname}:{port}/{ontology};transportMode=http;ssl={enabled_ssl};httpPath={http_path}",
    username,
    password
  )

Execute a query

Execute using the connection

  # Use the connection to execute a query
  with conn.cursor() as curs:
    # Execute query
    curs.execute('SHOW CONCEPTS')
    # Fetch results
    concepts = curs.fetchall()
    # Print the results
    for concept in concepts:
      print(concept)

Execute using the Pandas

  # Execute a query using Pandas
  df = pandas.read_sql("SELECT * FROM timbr.person limit 1000", conn)
  print("--------------------------------------")
  print(df)
  print("--------------------------------------")
  print(df.columns)
  print("--------------------------------------")
  print(df.count())

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

pytimbr-1.0.4.tar.gz (96.8 MB view details)

Uploaded Source

File details

Details for the file pytimbr-1.0.4.tar.gz.

File metadata

  • Download URL: pytimbr-1.0.4.tar.gz
  • Upload date:
  • Size: 96.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pytimbr-1.0.4.tar.gz
Algorithm Hash digest
SHA256 e4abed85be5e4f1a11e7c0417993a04a1a59a9b9ea28da9ae0cb4f795d771435
MD5 d44e61dd7fd3a965a797359b36b724cd
BLAKE2b-256 41eef2a40031cef17be357203a7cbe8a01456a64a745bad8a756a753cd1fce0a

See more details on using hashes here.

Supported by

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