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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: cnos_connector-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 4e2ce5bd3428fd0c7860e8f7bc86a3969d89d3c9e67aeae98f34934618446a1a
MD5 55375fd48ba49a806fe38d6365529d42
BLAKE2b-256 00288c41c6c27de4b83894d09b0b433414e12c438f6ead24bc19501dd9bf01d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cnos_connector-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e80f03efef935b94e5f9ac62ae99c3c71425fa003e29a88297b06af271ded046
MD5 1e3d6bb14e09f06aa8201ac39e230240
BLAKE2b-256 8d0921b30d3de89c36070bccf913a1fa0f3643b7403c177b24c9175c9e8d3328

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