Skip to main content

CnosDB Python Client

Project description

CnosDB Python Connector

CnosDB Python Connector repository contains the Python client library for the CnosDB. cnosdb_connector adapted for PEP249.

Installation

use pip install it from pypi, Python 3.6 or later is required.

pip install cnos-connector

Then import the package:

import cnosdb_connector

Getting Started

Query use SQL

from cnosdb_connector import connect

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")
resp = conn.execute("SHOW DATABASES")
print(resp)

Query use interface

from cnosdb_connector import connect

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")
conn.create_database("air")
resp = conn.list_database()
print(resp)

Query use PEP-249

from cnosdb_connector import connect

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")
cursor = conn.cursor()

cursor.execute("SHOW DATABASES")
resp = cursor.fetchall()
print(resp)

Query use pandas

import pandas as pd
from cnosdb_connector import connect

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")

resp = pd.read_sql("SHOW DATABASES", conn)
print(resp)

Write use LineProtocol

from cnosdb_connector import connect

line0 = "test_insert,ta=a1,tb=b1 fa=1,fb=2 1"
line1 = "test_insert,ta=a1,tb=b1 fa=3,fb=4 2"
line2 = "test_insert,ta=a1,tb=b1 fa=5,fb=6 3"

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")

conn.create_database_with_ttl("test_database", "100000d")
conn.switch_database("test_database")

conn.write_lines([line0, line1, line2])

resp = conn.execute("SELECT * FROM test_insert;")
print(resp)

Write use SQL

from cnosdb_connector import connect

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")

query = "insert test_insert(TIME, column1, column2, column3, column4, column5, column6, column7) values (100, -1234, 'hello', 1234, false, 1.2, 'beijing', 'shanghai'); "

conn.execute(query)

resp = conn.execute("SELECT * FROM test_insert;")
print(resp)

Write use CSV

from cnosdb_connector import connect
import os

query = "CREATE TABLE test_insert(column1 BIGINT CODEC(DELTA),\
                                  column2 BOOLEAN,\
                                  column3 DOUBLE CODEC(GORILLA),\
                                  TAGS(column4));"

conn = connect(url="http://127.0.0.1:31007/", user="root", password="")
# table schema must same with csv file
conn.execute(query)

path = os.path.abspath("test.csv")
conn.write_csv("test_insert", path)

resp = conn.execute("SELECT * FROM test_insert;")
print(resp)

License

CnosDB Python Connector use MIT License

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

cnos_connector-0.1.9.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

cnos_connector-0.1.9-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file cnos_connector-0.1.9.tar.gz.

File metadata

  • Download URL: cnos_connector-0.1.9.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for cnos_connector-0.1.9.tar.gz
Algorithm Hash digest
SHA256 cbb56e8af8f0cdb8917fb5f4fbf9c4db0b9cebfef2158d6c457c659e89c9b278
MD5 26b048ec6f29cdc56fce1273632efda1
BLAKE2b-256 2c98972c03479ab223b185968a06491fe4b5c16ffb53db110c2ca276d265fdd0

See more details on using hashes here.

File details

Details for the file cnos_connector-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for cnos_connector-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5c75ef67207d7d3d654200693e5f86f7191990dbd5eb9f2289a23f6da822b14a
MD5 5337721cca16331c9f05173a5ddb84e9
BLAKE2b-256 bda231cc635604ecc879c3cb5c37a7bfdb7261af7c5fc74925b1f48204bf775e

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