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.7.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

cnos_connector-0.1.7-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cnos_connector-0.1.7.tar.gz
  • Upload date:
  • Size: 6.0 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.7.tar.gz
Algorithm Hash digest
SHA256 15f10578b24fc466cca686d459b7feb8bb96dcc74c0444364055d07bdb1d8e0f
MD5 28a9eb6008aa7ca9f3e37340771b3e24
BLAKE2b-256 00cbcfc56054dfa763d1faf4d31cd96c799b069a738b877c083ce7a0fedbbe26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cnos_connector-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 905addda47a02d9a79d49b7f040b8b0932ad6891f30ae0e917408b1d97f81ad1
MD5 a18df62fa1577e5f814eff9606e495e2
BLAKE2b-256 ba85e4470a823ecc9789db2196b9fe0135e54f1ab60639a560e61729e42d3f57

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