Chapter 46. PL/Python — Python Procedural Language

|Chapter 46. PL/Python — Python Procedural Language|                             |                          |                  |                               |
|:------------------------------------------------:|-----------------------------|--------------------------|------------------|-------------------------------|
|        [Prev](plperl-under-the-hood.html)        |[Up](server-programming.html)|Part V. Server Programming|[Home](index.html)| [Next](plpython-python23.html)|

---

## Chapter 46. PL/Python — Python Procedural Language

**Table of Contents**

[46.1. Python 2 vs. Python 3](plpython-python23.html)[46.2. PL/Python Functions](plpython-funcs.html)[46.3. Data Values](plpython-data.html)[46.3.1. Data Type Mapping](plpython-data.html#id-1.8.11.11.3)[46.3.2. Null, None](plpython-data.html#id-1.8.11.11.4)[46.3.3. Arrays, Lists](plpython-data.html#PLPYTHON-ARRAYS)[46.3.4. Composite Types](plpython-data.html#id-1.8.11.11.6)[46.3.5. Set-Returning Functions](plpython-data.html#id-1.8.11.11.7)[46.4. Sharing Data](plpython-sharing.html)[46.5. Anonymous Code Blocks](plpython-do.html)[46.6. Trigger Functions](plpython-trigger.html)[46.7. Database Access](plpython-database.html)[46.7.1. Database Access Functions](plpython-database.html#id-1.8.11.15.3)[46.7.2. Trapping Errors](plpython-database.html#PLPYTHON-TRAPPING)[46.8. Explicit Subtransactions](plpython-subtransaction.html)[46.8.1. Subtransaction Context Managers](plpython-subtransaction.html#id-1.8.11.16.3)[46.8.2. Older Python Versions](plpython-subtransaction.html#id-1.8.11.16.4)[46.9. Transaction Management](plpython-transactions.html)[46.10. Utility Functions](plpython-util.html)[46.11. Environment Variables](plpython-envar.html)

[]()[]()

 The PL/Python procedural language allows PostgreSQL functions and procedures to be written in the [Python language](https://www.python.org).

 To install PL/Python in a particular database, use `CREATE EXTENSION plpythonu` (but see also [Section 46.1](plpython-python23.html)).

### Tip

 If a language is installed into `template1`, all subsequently created databases will have the language installed automatically.

 PL/Python is only available as an “untrusted” language, meaning it does not offer any way of restricting what users can do in it and is therefore named `plpythonu`. A trusted variant `plpython` might become available in the future if a secure execution mechanism is developed in Python. The writer of a function in untrusted PL/Python must take care that the function cannot be used to do anything unwanted, since it will be able to do anything that could be done by a user logged in as the database administrator. Only superusers can create functions in untrusted languages such as `plpythonu`.

### Note

 Users of source packages must specially enable the build of PL/Python during the installation process. (Refer to the installation instructions for more information.) Users of binary packages might find PL/Python in a separate subpackage.

---

|[Prev](plperl-under-the-hood.html)|[Up](server-programming.html)| [Next](plpython-python23.html)|
|:---------------------------------|:---------------------------:|------------------------------:|
|   45.8. PL/Perl Under the Hood   |     [Home](index.html)      |  46.1. Python 2 vs. Python 3  |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>