# micropg_lite V3
**The world's lightest PostgreSQL driver for MicroPython, made for ESP8266**
This README contains the most important things you need to know about micropg_lite. You can find detailed documentation in the [wiki of this repository](https://github.com/TimonW-Dev/micropg_lite/wiki).
If there are any problems, questions, bugs or suggestions for improvement, please open an [issue](https://github.com/TimonW-Dev/micropg_lite/issues) on this Github repository or write an email to the email address linked in [my profile](https://github.com/TimonW-Dev). We are happy to provide the necessary free support to help you with your micropg_lite requests.
## About micropg_lite
### Difference between [micropg_lite](https://github.com/TimonW-Dev/micropg_lite) and [micropg](https://github.com/nakagami/micropg)
[micropg_lite](https://github.com/TimonW-Dev/micropg_lite) is a lightweight version based on [micropg](https://github.com/nakagami/micropg) by [
nakagami](https://github.com/nakagami). If you have RAM/memory issues with [micropg](https://github.com/nakagami/micropg) than this library might solve this issue.
micropg_lite has been specially optimised for the ESP8266 microchip and other microchips that have little RAM. micopg_lite works on any microchip that runs micropyhton.
### Major changes in micropg_lite V3
Those who have already worked with micropg_lite V2 know that the micropg_lite V2 driver has some limitations in terms of functionality. Therefore, micropg_lite V3 was optimized from scratch to bring back the functionality that is present in [Nakagami's](https://github.com/nakagami) [micropg](https://github.com/nakagami/micropg).
## Installation
1. Download the `micropg_lite.py` file from [github.com](https://github.com/TimonW-Dev/micropg_lite) or [pypi.org](https://pypi.org/project/micropg-lite/#files) to your local computer.
2. Copy the `micropg_lite.py` file to the "/lib" folder on the microcontroller using the Thonny IDE or another program. If there is no "lib" folder in the root directory, you have to create it.
**Hint** for the Thony IDE:
Open in the top bar the "View" menu and make sure that the entry "Files" has a "+", if not then click on "Files". Now you can directly download and upload files from your computer to the microcontroller. You also can create folders on the microcontroller.
3. Now you should be able to import the library to your microcontroller in a MicroPython file.
````python
import micropg_lite
````
## microcontroller file tree
````
/
|- example.py
|- lib/
|- micropg_lite.py
````
## Examples
You need to establish a network connection before executing micropg_lite code. The [SELECT example](#select-example-with-wifi-connection) inclueds the wifi template. All other examples do not include the wifi template.
### examples/ folder on [github.com](https://github.com/TimonW-Dev/micropg_lite/tree/main/examples)
The [examples](https://github.com/TimonW-Dev/micropg_lite/tree/main/examples) folder has a [docker-postgres-container-setup.sh](https://github.com/TimonW-Dev/micropg_lite/blob/main/examples/docker-postgres-container-setup.sh) script to create an empty PostgreSQL container and an [exampleDatabase.sql](https://github.com/TimonW-Dev/micropg_lite/blob/main/examples/exampleDatabase.sql) file which contains the database used in the examples. You will also find complete test scripts with WLAN connection templates and examples for CREATE/DROP TABLE and DATABASE in the examples folder.
### SELECT example with wifi connection:
````python
import time
import network # Handles the wifi connection
import micropg_lite
### To Do: Fill in your wifi connection data and change the server data
ssid = 'wifissid'
password = 'secret'
# Connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
print("Wifi Status: ", wlan.status())
time.sleep(1)
print("Wifi connected")
conn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server
user='postgres',
password='123456',
database='exampledatabase')
cur = conn.cursor()
cur.execute('select * from customers')
selectresult = cur.fetchall()
conn.close()
# EXAMPLE: Print raw data
print(selectresult)
# EXAMPLE: Print data table
for r1 in selectresult:
for r2 in r1:
print(r2, end="\t")
print()
````
### INSERT example
````python
conn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server
user='postgres',
password='123456',
database='exampledatabase')
cur = conn.cursor()
cur.execute('INSERT INTO customers (id, firstName, lastName, email) values (%s, %s, %s, %s)', ['5', 'David', 'Wilson', 'david.wilson@example.com'])
conn.commit()
conn.close()
````
### UPDATE example
```` python
conn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server
user='postgres',
password='123456',
database='exampledatabase')
cur = conn.cursor()
cur.execute("update customers set firstName='UpdatedFirstName' where id=2;")
conn.commit()
conn.close()
````
### DELETE example
```` python
conn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server
user='postgres',
password='123456',
database='exampledatabase')
cur = conn.cursor()
cur.execute("delete from customers where id=1;")
conn.commit()
conn.close()
````
## micropg_lite limitations
- reduced error handling
- no MD5 auth method support
- No native support for the so-called "executemany" function
Raw data
{
"_id": null,
"home_page": "https://github.com/TimonW-Dev/micropg_lite",
"name": "micropg-lite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": null,
"keywords": "micropython postgresql esp8266 database",
"author": "TimonW-Dev",
"author_email": "timon-github@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/33/d5/741603a6c2990bc0bbe332c50c26dbd17c8f74ecfc15542f8237cf7bca14/micropg_lite-3.1.1.tar.gz",
"platform": null,
"description": "# micropg_lite V3 \r\n**The world's lightest PostgreSQL driver for MicroPython, made for ESP8266**\r\n\r\nThis README contains the most important things you need to know about micropg_lite. You can find detailed documentation in the [wiki of this repository](https://github.com/TimonW-Dev/micropg_lite/wiki).\r\n\r\nIf there are any problems, questions, bugs or suggestions for improvement, please open an [issue](https://github.com/TimonW-Dev/micropg_lite/issues) on this Github repository or write an email to the email address linked in [my profile](https://github.com/TimonW-Dev). We are happy to provide the necessary free support to help you with your micropg_lite requests.\r\n\r\n## About micropg_lite\r\n### Difference between [micropg_lite](https://github.com/TimonW-Dev/micropg_lite) and [micropg](https://github.com/nakagami/micropg)\r\n\r\n[micropg_lite](https://github.com/TimonW-Dev/micropg_lite) is a lightweight version based on [micropg](https://github.com/nakagami/micropg) by [\r\nnakagami](https://github.com/nakagami). If you have RAM/memory issues with [micropg](https://github.com/nakagami/micropg) than this library might solve this issue.\r\n\r\nmicropg_lite has been specially optimised for the ESP8266 microchip and other microchips that have little RAM. micopg_lite works on any microchip that runs micropyhton.\r\n\r\n### Major changes in micropg_lite V3\r\nThose who have already worked with micropg_lite V2 know that the micropg_lite V2 driver has some limitations in terms of functionality. Therefore, micropg_lite V3 was optimized from scratch to bring back the functionality that is present in [Nakagami's](https://github.com/nakagami) [micropg](https://github.com/nakagami/micropg).\r\n\r\n## Installation\r\n\r\n1. Download the `micropg_lite.py` file from [github.com](https://github.com/TimonW-Dev/micropg_lite) or [pypi.org](https://pypi.org/project/micropg-lite/#files) to your local computer.\r\n\r\n2. Copy the `micropg_lite.py` file to the \"/lib\" folder on the microcontroller using the Thonny IDE or another program. If there is no \"lib\" folder in the root directory, you have to create it.\r\n\r\n **Hint** for the Thony IDE:\r\n \r\n Open in the top bar the \"View\" menu and make sure that the entry \"Files\" has a \"+\", if not then click on \"Files\". Now you can directly download and upload files from your computer to the microcontroller. You also can create folders on the microcontroller.\r\n\r\n3. Now you should be able to import the library to your microcontroller in a MicroPython file.\r\n\r\n````python\r\nimport micropg_lite\r\n````\r\n\r\n## microcontroller file tree\r\n````\r\n/\r\n|- example.py\r\n|- lib/\r\n |- micropg_lite.py\r\n````\r\n\r\n## Examples\r\nYou need to establish a network connection before executing micropg_lite code. The [SELECT example](#select-example-with-wifi-connection) inclueds the wifi template. All other examples do not include the wifi template.\r\n\r\n### examples/ folder on [github.com](https://github.com/TimonW-Dev/micropg_lite/tree/main/examples)\r\nThe [examples](https://github.com/TimonW-Dev/micropg_lite/tree/main/examples) folder has a [docker-postgres-container-setup.sh](https://github.com/TimonW-Dev/micropg_lite/blob/main/examples/docker-postgres-container-setup.sh) script to create an empty PostgreSQL container and an [exampleDatabase.sql](https://github.com/TimonW-Dev/micropg_lite/blob/main/examples/exampleDatabase.sql) file which contains the database used in the examples. You will also find complete test scripts with WLAN connection templates and examples for CREATE/DROP TABLE and DATABASE in the examples folder.\r\n\r\n### SELECT example with wifi connection:\r\n````python\r\nimport time\r\nimport network # Handles the wifi connection\r\nimport micropg_lite\r\n\r\n### To Do: Fill in your wifi connection data and change the server data\r\nssid = 'wifissid'\r\npassword = 'secret'\r\n\r\n# Connect to network\r\nwlan = network.WLAN(network.STA_IF)\r\nwlan.active(True)\r\nwlan.connect(ssid, password)\r\n\r\nwhile not wlan.isconnected():\r\n print(\"Wifi Status: \", wlan.status())\r\n time.sleep(1)\r\n\r\n\r\nprint(\"Wifi connected\")\r\n\r\nconn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server\r\n user='postgres',\r\n password='123456',\r\n database='exampledatabase')\r\ncur = conn.cursor()\r\n\r\ncur.execute('select * from customers')\r\nselectresult = cur.fetchall()\r\nconn.close()\r\n\r\n# EXAMPLE: Print raw data\r\nprint(selectresult)\r\n\r\n# EXAMPLE: Print data table\r\nfor r1 in selectresult:\r\n for r2 in r1:\r\n print(r2, end=\"\\t\")\r\n print()\r\n````\r\n\r\n### INSERT example\r\n````python\r\nconn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server\r\n user='postgres',\r\n password='123456',\r\n database='exampledatabase')\r\ncur = conn.cursor()\r\n\r\ncur.execute('INSERT INTO customers (id, firstName, lastName, email) values (%s, %s, %s, %s)', ['5', 'David', 'Wilson', 'david.wilson@example.com'])\r\nconn.commit()\r\nconn.close()\r\n\r\n````\r\n\r\n### UPDATE example\r\n```` python\r\nconn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server\r\n user='postgres',\r\n password='123456',\r\n database='exampledatabase')\r\ncur = conn.cursor()\r\n\r\ncur.execute(\"update customers set firstName='UpdatedFirstName' where id=2;\")\r\nconn.commit()\r\nconn.close()\r\n````\r\n\r\n### DELETE example\r\n```` python\r\nconn = micropg_lite.connect(host='127.0.0.1', # To Do: Replace this string with the IP address of your server\r\n user='postgres',\r\n password='123456',\r\n database='exampledatabase')\r\ncur = conn.cursor()\r\n\r\ncur.execute(\"delete from customers where id=1;\")\r\nconn.commit()\r\nconn.close()\r\n\r\n````\r\n\r\n## micropg_lite limitations\r\n- reduced error handling\r\n- no MD5 auth method support\r\n- No native support for the so-called \"executemany\" function\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A lightweight PostgreSQL database driver for MicroPython, designed for microcontrollers (e.g., ESP8266) with limited RAM.",
"version": "3.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/TimonW-Dev/micropg_lite/issues",
"Documentation": "https://github.com/TimonW-Dev/micropg_lite/wiki",
"Homepage": "https://github.com/TimonW-Dev/micropg_lite",
"Source Code": "https://github.com/TimonW-Dev/micropg_lite"
},
"split_keywords": [
"micropython",
"postgresql",
"esp8266",
"database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e0c9e77166c198211a7132509f0cb2ef5dce9e0af72dccefcc11965da84a23cf",
"md5": "1bb8e809eeb616b8494a7935de5f7d0c",
"sha256": "23edec5e64a25f4f69824b8def3645456a73bb5dad2ae3860bcca6394b5fe33e"
},
"downloads": -1,
"filename": "micropg_lite-3.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1bb8e809eeb616b8494a7935de5f7d0c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 6733,
"upload_time": "2025-01-25T20:14:18",
"upload_time_iso_8601": "2025-01-25T20:14:18.185347Z",
"url": "https://files.pythonhosted.org/packages/e0/c9/e77166c198211a7132509f0cb2ef5dce9e0af72dccefcc11965da84a23cf/micropg_lite-3.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "33d5741603a6c2990bc0bbe332c50c26dbd17c8f74ecfc15542f8237cf7bca14",
"md5": "af77ed32c5e3e410df633135ebf74416",
"sha256": "ba04814b2a6b45bac3977c5c812324e39b4ef8a4e7ca7ef2db1f03447bcf6e1e"
},
"downloads": -1,
"filename": "micropg_lite-3.1.1.tar.gz",
"has_sig": false,
"md5_digest": "af77ed32c5e3e410df633135ebf74416",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 6769,
"upload_time": "2025-01-25T20:14:19",
"upload_time_iso_8601": "2025-01-25T20:14:19.326422Z",
"url": "https://files.pythonhosted.org/packages/33/d5/741603a6c2990bc0bbe332c50c26dbd17c8f74ecfc15542f8237cf7bca14/micropg_lite-3.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-25 20:14:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TimonW-Dev",
"github_project": "micropg_lite",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "micropg-lite"
}