{"id":46579,"date":"2018-12-21T00:00:00","date_gmt":"2018-12-21T08:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/updated-python-griddb-api\/"},"modified":"2025-11-13T12:54:42","modified_gmt":"2025-11-13T20:54:42","slug":"updated-python-griddb-api","status":"publish","type":"post","link":"https:\/\/www.griddb.net\/en\/blog\/updated-python-griddb-api\/","title":{"rendered":"Updated Python GridDB API"},"content":{"rendered":"<p>Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of connecting, querying, writing records, and other common operations.<\/p>\n<h1>Installing<\/h1>\n<p>The <a href='https:\/\/griddb.net\/en\/blog\/griddb-quickstart\/'>Quickstart Blog<\/a> has Python installation instructions.<\/p>\n<h1>Connecting<\/h1>\n<p>Connecting to GridDB is a single call that takes a list of parameters. If you&#8217;re using GridDB in fixed list mode, specify notification_member instead of host and port.<\/p>\n<div class=\"clipboard\">\n<pre class=\"language-python\"><code>self.gridstore = factory.get_store(\n    host=\"239.0.0.1\",\n    port=\"31999\",\n    cluster_name=\"defaultCluster\",\n    username=\"admin\",\n    password=\"admin\"\n)<\/code>\n<\/pre>\n<\/div>\n<h1>Querying<\/h1>\n<p>To query GridDB, you first open the container you wish to query, specify and execute the query, and then fetch and iterate through the results. Specifying timestamp_output_with_float will make GridDB not convert TIMESTAMP fields into Python datetime objects improving performance significantly.<\/p>\n<div class=\"clipboard\">\n<pre class=\"language-python\"><code>try:\n    cn = gridstore.get_container(\"DEVICE_READS\");\n    query = cn.query(\"select *\")\n    rs = query.fetch(False)\n    rs.timestamp_output_with_float = True\nexcept:\n    return []\nretval= []\nwhile rs.has_next():\n    data = rs.next()\n    retval.append(data)<\/code>\n<\/pre>\n<\/div>\n<h1>Writing<\/h1>\n<p>To write to GridDB, you specify the container schema as an array of fields and their type and then open the container with put_container. Data is written using put or multi_put calls.<\/p>\n<div class=\"clipboard\">\n<pre class=\"language-python\"><code>conInfo = griddb.ContainerInfo(\"DEVICE_READS\",\n    [[\"ts\", griddb.Type.TIMESTAMP],\n    [\"attr\", griddb.Type.STRING],\n    [\"value\", griddb.Type.LONG]],\n    griddb.ContainerType.TIME_SERIES, True)\nts = gridstore.put_container(conInfo)\nts.set_auto_commit(False)\nts.put([int(datetime.datetime.now().timestamp()*1000), \"foo\", 42.0])\nts.commit()<\/code>\n<\/pre>\n<\/div>\n<h1>Updating<\/h1>\n<p>Updates combine queries and writes. Open a container using a ContainerInfo object, query and iterate through the results which will update and commit the updated rows. The parameter of query_fetch should be True, this allows GridDB to update the result set.<\/p>\n<div class=\"clipboard\">\n<pre class=\"language-python\"><code>conInfo = griddb.ContainerInfo(\"DEVICE_READS\",\n    [[\"ts\", griddb.Type.TIMESTAMP],\n    [\"attr\", griddb.Type.STRING],\n    [\"value\", griddb.Type.LONG]],\n    griddb.ContainerType.TIME_SERIES, True)\nts = gridstore.put_container(conInfo)\nts.set_auto_commit(False)\nquery = ts.query(\"select * where ts < TO_TIMESTAMP_MS(\"+str(epochTs)+\")\")\nrs = query.fetch(True)\nif rs.has_next():\n    data = idx_rs.next()\n    rs.update([data[0], \"old_\"+data[1], data[2]])\n    rs.commit()<\/code>\n<\/pre>\n<\/div>\n<h1>Deleting<\/h1>\n<p>Deleting a row in the container queried is very similar to the update process; the main difference being calling remove with the row key as a parameter instead.<\/p>\n<div class=\"clipboard\">\n<pre class=\"language-python\"><code>conInfo = griddb.ContainerInfo(\"DEVICE_READS\",\n    [[\"ts\", griddb.Type.TIMESTAMP],\n    [\"attr\", griddb.Type.STRING],\n    [\"value\", griddb.Type.LONG]],\n    griddb.ContainerType.TIME_SERIES, True)\nts = sgridstore.put_container(conInfo)\nts.set_auto_commit(False)\nquery = ts.query(\"select * where attr = '\"+specifiedAttr+\"'\")\nrs = query.fetch(True)\nif rs.has_next():\n    data = idx_rs.next()\n    rs.remove(data[0])\n    rs.commit()<\/code>\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of connecting, querying, writing records, and other common operations. Installing The Quickstart Blog has Python installation instructions. Connecting Connecting to GridDB is a single call that takes a list of parameters. If [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":22052,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-46579","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-21T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T20:54:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.griddb.net\/wp-content\/uploads\/2017\/09\/blog_title_17.png\" \/>\n\t<meta property=\"og:image:width\" content=\"870\" \/>\n\t<meta property=\"og:image:height\" content=\"490\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Owen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Owen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\"},\"author\":{\"name\":\"Owen\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/0f2f6d4b593adde8c43cf3ea5c794c66\"},\"headline\":\"Updated Python GridDB API\",\"datePublished\":\"2018-12-21T08:00:00+00:00\",\"dateModified\":\"2025-11-13T20:54:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\"},\"wordCount\":226,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2017\/09\/blog_title_17.png\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\",\"name\":\"Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2017\/09\/blog_title_17.png\",\"datePublished\":\"2018-12-21T08:00:00+00:00\",\"dateModified\":\"2025-11-13T20:54:42+00:00\",\"description\":\"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2017\/09\/blog_title_17.png\",\"contentUrl\":\"\/wp-content\/uploads\/2017\/09\/blog_title_17.png\",\"width\":870,\"height\":490},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb.net\/en\/#website\",\"url\":\"https:\/\/griddb.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/0f2f6d4b593adde8c43cf3ea5c794c66\",\"name\":\"Owen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/47438a5c81215c7a9043be1b427e0bbd8dc0f77bd536f147f8495575149e4325?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/47438a5c81215c7a9043be1b427e0bbd8dc0f77bd536f147f8495575149e4325?s=96&d=mm&r=g\",\"caption\":\"Owen\"},\"url\":\"https:\/\/www.griddb.net\/en\/author\/owen\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT","description":"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/","og_locale":"en_US","og_type":"article","og_title":"Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT","og_description":"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of","og_url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2018-12-21T08:00:00+00:00","article_modified_time":"2025-11-13T20:54:42+00:00","og_image":[{"width":870,"height":490,"url":"https:\/\/www.griddb.net\/wp-content\/uploads\/2017\/09\/blog_title_17.png","type":"image\/png"}],"author":"Owen","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"Owen","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#article","isPartOf":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/"},"author":{"name":"Owen","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/0f2f6d4b593adde8c43cf3ea5c794c66"},"headline":"Updated Python GridDB API","datePublished":"2018-12-21T08:00:00+00:00","dateModified":"2025-11-13T20:54:42+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/"},"wordCount":226,"commentCount":0,"publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2017\/09\/blog_title_17.png","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/","name":"Updated Python GridDB API | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2017\/09\/blog_title_17.png","datePublished":"2018-12-21T08:00:00+00:00","dateModified":"2025-11-13T20:54:42+00:00","description":"Earlier this year, an updated Python Client for GridDB was released (0.7.0) which provides an improved API. This blog post covers the basics of","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/updated-python-griddb-api\/#primaryimage","url":"\/wp-content\/uploads\/2017\/09\/blog_title_17.png","contentUrl":"\/wp-content\/uploads\/2017\/09\/blog_title_17.png","width":870,"height":490},{"@type":"WebSite","@id":"https:\/\/griddb.net\/en\/#website","url":"https:\/\/griddb.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/0f2f6d4b593adde8c43cf3ea5c794c66","name":"Owen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/47438a5c81215c7a9043be1b427e0bbd8dc0f77bd536f147f8495575149e4325?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/47438a5c81215c7a9043be1b427e0bbd8dc0f77bd536f147f8495575149e4325?s=96&d=mm&r=g","caption":"Owen"},"url":"https:\/\/www.griddb.net\/en\/author\/owen\/"}]}},"_links":{"self":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/comments?post=46579"}],"version-history":[{"count":1,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46579\/revisions"}],"predecessor-version":[{"id":51268,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46579\/revisions\/51268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/media\/22052"}],"wp:attachment":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/media?parent=46579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/categories?post=46579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/tags?post=46579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}