{"id":766,"date":"2018-12-01T06:00:48","date_gmt":"2018-12-01T06:00:48","guid":{"rendered":"http:\/\/buklijas.info\/blog\/?p=766"},"modified":"2018-12-14T21:12:52","modified_gmt":"2018-12-14T21:12:52","slug":"introductio-to-python-packet-dataset","status":"publish","type":"post","link":"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/","title":{"rendered":"Introduction to Python packet Dataset"},"content":{"rendered":"

Published on:<\/strong> 01.12.2018<\/p>\n

Python packet dataset<\/a> describes itself as databases for lazy people<\/strong> and they are correct.<\/p>\n

For saving data with dataset all you need is just a Python dictionary<\/strong>, the keys of the dictionary are columns in a table and that is all.<\/p>\n

\nimport dataset\n\ndb = dataset.connect('sqlite:\/\/\/:memory:')\n\ntable = db['sometable']\ntable.insert(dict(name='John Doe', age=37))\ntable.insert(dict(name='Jane Doe', age=34, gender='female'))\n\njohn = table.find_one(name='John Doe')\n<\/pre>\n

Dataset will automatically make all tables and columns necessary<\/strong>.<\/p>\n

Internal data is stored in SQLite, PostgreSQL or MySQL database<\/strong>, my experience has only been with SQLite so far.<\/p>\n

My experience<\/h3>\n

In one project I use it just for memory database<\/strong>, after scraping data from a website it is stored in-memory SQLite.<\/p>\n

Then I can use standard dataset API to retrieve data with certain criteria and sort it, before emailing it.<\/p>\n

On another project, I use it to store data in SQLite<\/strong> and later to retrieve it.<\/p>\n

I must admit that for everything else than basic searching, filtering and sorting you have to write SQL queries<\/a>.<\/p>\n

One useful feature is upsert<\/a>, upsert is a smart combination of insert and update<\/strong>.<\/p>\n

If rows with matching keys exist they will be updated, otherwise a new row is inserted in the table<\/strong>.<\/p>\n

There is also a feature to export data<\/a> to CSV or JSON.<\/p>\n

Conclusion<\/h3>\n

If you think that using DB on your next project is overkill, but you do need to filter, search or sort data, take a look at datase<\/strong>.<\/p>\n

It is much better than to make custom solutions, I know because I did stored data in pickle format<\/a> and wrote a custom function for filtering, sorting and retrieving data from pickle, before I learned about dataset<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

Published on: 01.12.2018 Python packet dataset describes itself as databases for lazy people and they are correct. For saving data with dataset all you need is just a Python dictionary, the keys of the dictionary are columns in a table and that is all. import dataset db = dataset.connect(‘sqlite:\/\/\/:memory:’) table = db[‘sometable’] table.insert(dict(name=’John Doe’, age=37)) […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[27],"tags":[50,4],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"yoast_head":"\nIntroduction to Python packet Dataset - Sasa Buklijas<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Python packet Dataset - Sasa Buklijas\" \/>\n<meta property=\"og:description\" content=\"Published on: 01.12.2018 Python packet dataset describes itself as databases for lazy people and they are correct. For saving data with dataset all you need is just a Python dictionary, the keys of the dictionary are columns in a table and that is all. import dataset db = dataset.connect('sqlite:\/\/\/:memory:') table = db['sometable'] table.insert(dict(name='John Doe', age=37)) […]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/\" \/>\n<meta property=\"og:site_name\" content=\"Sasa Buklijas\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-01T06:00:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-12-14T21:12:52+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\">\n\t<meta name=\"twitter:data1\" content=\"Sasa Buklijas\">\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data2\" content=\"1 minute\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/buklijas.info\/blog\/#website\",\"url\":\"http:\/\/buklijas.info\/blog\/\",\"name\":\"Sasa Buklijas\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"http:\/\/buklijas.info\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/#webpage\",\"url\":\"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/\",\"name\":\"Introduction to Python packet Dataset - Sasa Buklijas\",\"isPartOf\":{\"@id\":\"http:\/\/buklijas.info\/blog\/#website\"},\"datePublished\":\"2018-12-01T06:00:48+00:00\",\"dateModified\":\"2018-12-14T21:12:52+00:00\",\"author\":{\"@id\":\"http:\/\/buklijas.info\/blog\/#\/schema\/person\/780025d597f1c5df3cc156eaffc8c561\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/buklijas.info\/blog\/2018\/12\/01\/introductio-to-python-packet-dataset\/\"]}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/buklijas.info\/blog\/#\/schema\/person\/780025d597f1c5df3cc156eaffc8c561\",\"name\":\"Sasa Buklijas\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/buklijas.info\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/9f6f7de5a4882517ca0e4a8ebd607925?s=96&d=mm&r=g\",\"caption\":\"Sasa Buklijas\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5YHGV-cm","_links":{"self":[{"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/posts\/766"}],"collection":[{"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/comments?post=766"}],"version-history":[{"count":5,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":788,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/posts\/766\/revisions\/788"}],"wp:attachment":[{"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/media?parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/categories?post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/buklijas.info\/blog\/wp-json\/wp\/v2\/tags?post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}