{"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 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 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 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":"\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
My experience<\/h3>\n
Conclusion<\/h3>\n