<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vertica Documentation – Python SDK</title>
    <link>/en/extending/developing-udxs/developing-with-sdk/python-sdk/</link>
    <description>Recent content in Python SDK on Vertica Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/extending/developing-udxs/developing-with-sdk/python-sdk/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Extending: Setting up a Python development environment</title>
      <link>/en/extending/developing-udxs/developing-with-sdk/python-sdk/setting-up-python-development-environment/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/developing-udxs/developing-with-sdk/python-sdk/setting-up-python-development-environment/</guid>
      <description>
        
        
        &lt;p&gt;To avoid problems when loading and executing your UDxs, develop your UDxs using the same version of Python that Vertica uses. To do this without changing your environment for projects that might require other Python versions, you can use a &lt;a href=&#34;https://docs.python.org/3/library/venv.html&#34;&gt;Python virtual environment (venv)&lt;/a&gt;. You can install libraries that your UDx depends on into your &lt;code&gt;venv&lt;/code&gt; and use that path when you create your UDx library with &lt;a href=&#34;../../../../../en/sql-reference/statements/create-statements/create-library/&#34;&gt;CREATE LIBRARY&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-venv&#34;&gt;Setting up venv&lt;/h2&gt;
&lt;p&gt;Set up &lt;code&gt;venv&lt;/code&gt; using the Python version bundled with Vertica. If you have direct access to a database node, you can use that Python binary directly to create your &lt;code&gt;venv&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ /opt/vertica/sbin/python3 -m venv /path/to/new/environment
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The result is a directory with a default environment, including a &lt;code&gt;site-packages&lt;/code&gt; directory:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ ls venv/lib/
python3.9
$ ls venv/lib/python3.9/
site-packages
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If your UDx depends on libraries that are not packaged with Vertica, install them into this directory:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ source venv/bin/activate
(venv) $ pip install numpy
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;lib/python3.9/site-packages&lt;/code&gt; directory now contains the installed library. The change affects only your virtual environment.&lt;/p&gt;
&lt;h2 id=&#34;udx-imports&#34;&gt;UDx imports&lt;/h2&gt;
&lt;p&gt;Your UDx code must import, in addition to any libraries you add, the &lt;code&gt;vertica_sdk&lt;/code&gt; library:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# always required:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;vertica_sdk&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# other libs:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;numpy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;np&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# ...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;vertica_sdk&lt;/code&gt; library is included as a part of the Vertica server. You do not need to add it to &lt;code&gt;site-packages&lt;/code&gt; or declare it as a dependency.&lt;/p&gt;
&lt;h2 id=&#34;deployment&#34;&gt;Deployment&lt;/h2&gt;
&lt;p&gt;For libraries you add, you must declare dependencies when using &lt;a href=&#34;../../../../../en/sql-reference/statements/create-statements/create-library/&#34;&gt;CREATE LIBRARY&lt;/a&gt;. This declaration allows Vertica to find the libraries and distribute them to all database nodes. You can supply a path instead of enumerating the libraries:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE OR REPLACE LIBRARY pylib AS
   &amp;#39;/path/to/udx/add2ints.py&amp;#39;
   DEPENDS &amp;#39;/path/to/new/environment/lib/python3.9/site-packages/*&amp;#39;
   LANGUAGE &amp;#39;Python&amp;#39;;

=&amp;gt; CREATE OR REPLACE FUNCTION add2ints AS LANGUAGE &amp;#39;Python&amp;#39;
   NAME &amp;#39;add2ints_factory&amp;#39; LIBRARY pylib;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;CREATE LIBRARY copies the UDx and the contents of the DEPENDS path and stores them with the database. Vertica then distributes copies to all database nodes.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Extending: Python and Vertica data types</title>
      <link>/en/extending/developing-udxs/developing-with-sdk/python-sdk/python-and-data-types/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/extending/developing-udxs/developing-with-sdk/python-sdk/python-and-data-types/</guid>
      <description>
        
        
        &lt;p&gt;The Vertica Python SDK converts native Vertica data types into the appropriate Python data types. The following table describes some of the data type conversions. Consult the &lt;a href=&#34;../../../../../en/api-reference/python-sdk/&#34;&gt;Python SDK&lt;/a&gt; for a complete list, as well as lists of helper functions to convert and manipulate these data types.&lt;/p&gt;
&lt;p&gt;For information about SDK support for complex data types, see &lt;a href=&#34;../../../../../en/extending/developing-udxs/arguments-and-return-values/#Complex&#34;&gt;Complex Types as Arguments and Return Values&lt;/a&gt;.

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;th &gt;
Vertica Data Type&lt;/th&gt; 

&lt;th &gt;
Python Data Type&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
INTEGER&lt;/td&gt; 

&lt;td &gt;
int&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
FLOAT&lt;/td&gt; 

&lt;td &gt;
float&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
NUMERIC&lt;/td&gt; 

&lt;td &gt;
decimal.Decimal&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
DATE&lt;/td&gt; 

&lt;td &gt;
datetime.date&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
CHAR, VARCHAR, LONG VARCHAR&lt;/td&gt; 

&lt;td &gt;
string (UTF-8 encoded)&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
BINARY, VARBINARY, LONG VARBINARY&lt;/td&gt; 

&lt;td &gt;
binary&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
TIMESTAMP&lt;/td&gt; 

&lt;td &gt;
datetime.datetime&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
TIME&lt;/td&gt; 

&lt;td &gt;
datetime.time&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
ARRAY&lt;/td&gt; 

&lt;td &gt;




&lt;p&gt;list&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Nested ARRAY types are also converted into lists.&lt;/p&gt;
&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
ROW&lt;/td&gt; 

&lt;td &gt;




&lt;p&gt;collections.OrderedDict&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Nested ROW types are also converted into collections.OrderedDicts.&lt;/p&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Some Vertica data types are not supported in Python. For a list of all Vertica data types, see &lt;a href=&#34;../../../../../en/sql-reference/data-types/&#34;&gt;Data types&lt;/a&gt;.

&lt;/div&gt;&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
