-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathlibpython-clj2.python.html
More file actions
89 lines (89 loc) · 37.7 KB
/
libpython-clj2.python.html
File metadata and controls
89 lines (89 loc) · 37.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>libpython-clj2.python documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="highlight/solarized-light.css" /><script type="text/javascript" src="highlight/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a> with <a href="https://github.com/xsc/codox-theme-rdash">RDash UI</a> theme</h2><h1><a href="index.html"><span class="project-title"><span class="project-name"></span> <span class="project-version">2.006</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 "><a href="Usage.html"><div class="inner"><span>Usage</span></div></a></li><li class="depth-1 "><a href="design.html"><div class="inner"><span>LibPython-CLJ Design Notes</span></div></a></li><li class="depth-1 "><a href="embedded.html"><div class="inner"><span>Embedding Clojure In Python</span></div></a></li><li class="depth-1 "><a href="environments.html"><div class="inner"><span>Python Environments</span></div></a></li><li class="depth-1 "><a href="new-to-clojure.html"><div class="inner"><span>So Many Parenthesis!</span></div></a></li><li class="depth-1 "><a href="scopes-and-gc.html"><div class="inner"><span>Scopes And Garbage Collection</span></div></a></li><li class="depth-1 "><a href="slicing.html"><div class="inner"><span>Slicing And Slices</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>libpython-clj2</span></div></div></li><li class="depth-2 branch"><a href="libpython-clj2.codegen.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>codegen</span></div></a></li><li class="depth-2 branch"><a href="libpython-clj2.embedded.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>embedded</span></div></a></li><li class="depth-2 branch"><a href="libpython-clj2.java-api.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>java-api</span></div></a></li><li class="depth-2 current"><a href="libpython-clj2.python.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>python</span></div></a></li><li class="depth-3"><a href="libpython-clj2.python.np-array.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>np-array</span></div></a></li><li class="depth-2"><a href="libpython-clj2.require.html"><div class="inner"><span class="tree" style="top: -52px;"><span class="top" style="height: 61px;"></span><span class="bottom"></span></span><span>require</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="libpython-clj2.python.html#var-.24a"><div class="inner"><span>$a</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-.24c"><div class="inner"><span>$c</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var--.3Ejvm"><div class="inner"><span>->jvm</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var--.3Epy-dict"><div class="inner"><span>->py-dict</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var--.3Epy-list"><div class="inner"><span>->py-list</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var--.3Epy-tuple"><div class="inner"><span>->py-tuple</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var--.3Epython"><div class="inner"><span>->python</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-add-module"><div class="inner"><span>add-module</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-afn"><div class="inner"><span>afn</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-as-jvm"><div class="inner"><span>as-jvm</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-as-list"><div class="inner"><span>as-list</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-as-map"><div class="inner"><span>as-map</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-as-python"><div class="inner"><span>as-python</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-call-attr"><div class="inner"><span>call-attr</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-call-attr-kw"><div class="inner"><span>call-attr-kw</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-callable.3F"><div class="inner"><span>callable?</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-cfn"><div class="inner"><span>cfn</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-create-class"><div class="inner"><span>create-class</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-def-unpack"><div class="inner"><span>def-unpack</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-dir"><div class="inner"><span>dir</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-from-import"><div class="inner"><span>from-import</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-get-attr"><div class="inner"><span>get-attr</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-get-item"><div class="inner"><span>get-item</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-has-attr.3F"><div class="inner"><span>has-attr?</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-has-item.3F"><div class="inner"><span>has-item?</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-import-as"><div class="inner"><span>import-as</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-import-module"><div class="inner"><span>import-module</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-initialize.21"><div class="inner"><span>initialize!</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-is-instance.3F"><div class="inner"><span>is-instance?</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-make-callable"><div class="inner"><span>make-callable</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-make-instance-fn"><div class="inner"><span>make-instance-fn</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-make-kw-instance-fn"><div class="inner"><span>make-kw-instance-fn</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-module-dict"><div class="inner"><span>module-dict</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-path-.3Epy-obj"><div class="inner"><span>path->py-obj</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-py*"><div class="inner"><span>py*</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-py**"><div class="inner"><span>py**</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-py."><div class="inner"><span>py.</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-py.-"><div class="inner"><span>py.-</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-py.."><div class="inner"><span>py..</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-python-type"><div class="inner"><span>python-type</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-run-simple-string"><div class="inner"><span>run-simple-string</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-set-attr.21"><div class="inner"><span>set-attr!</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-set-attrs.21"><div class="inner"><span>set-attrs!</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-set-item.21"><div class="inner"><span>set-item!</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-set-items.21"><div class="inner"><span>set-items!</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-stack-resource-context"><div class="inner"><span>stack-resource-context</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-with"><div class="inner"><span>with</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-with-gil"><div class="inner"><span>with-gil</span></div></a></li><li class="depth-1"><a href="libpython-clj2.python.html#var-with-gil-stack-rc-context"><div class="inner"><span>with-gil-stack-rc-context</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">libpython-clj2.python</h1><div class="doc"><div class="markdown"><p>Python bindings for Clojure. This library dynamically finds the installed python, loads the shared library and allows Clojure users to use Python modules as if they were Clojure namespaces.</p>
<p>Example:</p>
<pre><code class="clojure">user> (require '[libpython-clj2.python :as py])
nil
user> (py/initialize!)
;; ... (logging)
:ok
user> (def np (py/import-module "numpy"))
#'user/np
user> (py/py. np linspace 2 3 :num 10)
[2. 2.11111111 2.22222222 2.33333333 2.44444444 2.55555556
2.66666667 2.77777778 2.88888889 3. ]
</code></pre></div></div><div class="public anchor" id="var-.24a"><h3>$a</h3><h4 class="type">macro</h4><div class="usage"><code>($a item attr & args)</code></div><div class="doc"><div class="markdown"><p>Call an attribute of an object using automatic detection of the python kwargs. Keywords must be compile time constants. So this won’t work with ‘apply’. On the other hand, building the positional and kw argmaps happens at compile time as opposed to at runtime. The attr name can be a symbol.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L509">view source</a></div></div><div class="public anchor" id="var-.24c"><h3>$c</h3><h4 class="type">macro</h4><div class="usage"><code>($c item & args)</code></div><div class="doc"><div class="markdown"><p>Call an object using automatic detection of the python kwargs. Keywords must be compile time constants. So this won’t work with ‘apply’. On the other hand, building the positional and kw argmaps happens at compile time as opposed to at runtime.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L520">view source</a></div></div><div class="public anchor" id="var--.3Ejvm"><h3>->jvm</h3><div class="usage"><code>(->jvm v & [opts])</code></div><div class="doc"><div class="markdown"><p>Copy a python value into java datastructures</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L262">view source</a></div></div><div class="public anchor" id="var--.3Epy-dict"><h3>->py-dict</h3><div class="usage"><code>(->py-dict v)</code></div><div class="doc"><div class="markdown"><p>Copy v into a python dict</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L356">view source</a></div></div><div class="public anchor" id="var--.3Epy-list"><h3>->py-list</h3><div class="usage"><code>(->py-list v)</code></div><div class="doc"><div class="markdown"><p>Copy the data into a python list</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L344">view source</a></div></div><div class="public anchor" id="var--.3Epy-tuple"><h3>->py-tuple</h3><div class="usage"><code>(->py-tuple v)</code></div><div class="doc"><div class="markdown"><p>Copy v into a python tuple</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L350">view source</a></div></div><div class="public anchor" id="var--.3Epython"><h3>->python</h3><div class="usage"><code>(->python v)</code></div><div class="doc"><div class="markdown"><p>Copy a jvm value into a python object</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L250">view source</a></div></div><div class="public anchor" id="var-add-module"><h3>add-module</h3><div class="usage"><code>(add-module modname)</code></div><div class="doc"><div class="markdown"><p>Add a python module. This can create a module if it doesn’t exist.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L164">view source</a></div></div><div class="public anchor" id="var-afn"><h3>afn</h3><div class="usage"><code>(afn item attr & args)</code></div><div class="doc"><div class="markdown"><p>Call an attribute of an object. Arguments are passed in positionally. Any keyword arguments are paired with the next arg, gathered, and passed into the system as *kwargs.</p>
<p>Not having an argument after a keyword is an error.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L490">view source</a></div></div><div class="public anchor" id="var-as-jvm"><h3>as-jvm</h3><div class="usage"><code>(as-jvm v & [opts])</code></div><div class="doc"><div class="markdown"><p>Copy a python value into java datastructures</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L268">view source</a></div></div><div class="public anchor" id="var-as-list"><h3>as-list</h3><div class="usage"><code>(as-list pobj)</code></div><div class="doc"><div class="markdown"><p>Make a python object appear as a list</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L280">view source</a></div></div><div class="public anchor" id="var-as-map"><h3>as-map</h3><div class="usage"><code>(as-map pobj)</code></div><div class="doc"><div class="markdown"><p>Make a python object appear as a map of it’s items</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L274">view source</a></div></div><div class="public anchor" id="var-as-python"><h3>as-python</h3><div class="usage"><code>(as-python v)</code></div><div class="doc"><div class="markdown"><p>Bridge a jvm value into a python object</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L256">view source</a></div></div><div class="public anchor" id="var-call-attr"><h3>call-attr</h3><div class="usage"><code>(call-attr pyobj attname & args)</code></div><div class="doc"><div class="markdown"><p>Call an attribute on a python object using only positional arguments</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L187">view source</a></div></div><div class="public anchor" id="var-call-attr-kw"><h3>call-attr-kw</h3><div class="usage"><code>(call-attr-kw pyobj attname args kw-list)</code></div><div class="doc"><div class="markdown"><p>Call an attribute passing in both positional and keyword arguments.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L193">view source</a></div></div><div class="public anchor" id="var-callable.3F"><h3>callable?</h3><div class="usage"><code>(callable? pyobj)</code></div><div class="doc"><div class="markdown"><p>Return true if python object is callable.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L327">view source</a></div></div><div class="public anchor" id="var-cfn"><h3>cfn</h3><div class="usage"><code>(cfn item & args)</code></div><div class="doc"><div class="markdown"><p>Call an object. Arguments are passed in positionally. Any keyword arguments are paired with the next arg, gathered, and passed into the system as *kwargs.</p>
<p>Not having an argument after a keyword argument is an error.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L479">view source</a></div></div><div class="public anchor" id="var-create-class"><h3>create-class</h3><div class="usage"><code>(create-class name bases cls-hashmap)</code></div><div class="doc"><div class="markdown"><p>Create a new class object. Any callable values in the cls-hashmap will be presented as instance methods. If you want access to the ‘this’ object then you must use <code>make-instance-fn</code>.</p>
<p>Example:</p>
<pre><code class="clojure">user> (require '[libpython-clj2.python :as py])
nil
user> (def cls-obj (py/create-class
"myfancyclass"
nil
{"__init__" (py/make-instance-fn
(fn [this arg]
(py/set-attr! this "arg" arg)
;;If you don't return nil from __init__ that is an
;;error.
nil))
"addarg" (py/make-instance-fn
(fn [this otherarg]
(+ (py/get-attr this "arg")
otherarg)))}))
#'user/cls-obj
user> cls-obj
__no_module__.myfancyclass
user> (def inst (cls-obj 10))
#'user/inst
user> (py/call-attr inst "addarg" 10)
20
</code></pre></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L444">view source</a></div></div><div class="public anchor" id="var-def-unpack"><h3>def-unpack</h3><h4 class="type">macro</h4><div class="usage"><code>(def-unpack symbols input)</code></div><div class="doc"><div class="markdown"><p>Unpack a set of symbols into a set of defs. Useful when trying to match Python idioms - this is definitely not idiomatic Clojure.</p>
<p>Example:</p>
<pre><code class="clojure">user> (py/def-unpack [a b c] (py/->py-tuple [1 2 3]))
#'user/c
user> a
1
user> b
2
user> c
3
</code></pre></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L682">view source</a></div></div><div class="public anchor" id="var-dir"><h3>dir</h3><div class="usage"><code>(dir pyobj)</code></div><div class="doc"><div class="markdown"></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L182">view source</a></div></div><div class="public anchor" id="var-from-import"><h3>from-import</h3><h4 class="type">macro</h4><div class="usage"><code>(from-import module-path item & args)</code></div><div class="doc"><div class="markdown"><p>Support for the from a import b,c style of importing modules and symbols in python. Documentation is included.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L301">view source</a></div></div><div class="public anchor" id="var-get-attr"><h3>get-attr</h3><div class="usage"><code>(get-attr pyobj attname)</code></div><div class="doc"><div class="markdown"><p>Get an attribute from a python object</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L198">view source</a></div></div><div class="public anchor" id="var-get-item"><h3>get-item</h3><div class="usage"><code>(get-item pyobj item-name)</code></div><div class="doc"><div class="markdown"><p>Get an item from a python object using <strong>getitem</strong></p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L224">view source</a></div></div><div class="public anchor" id="var-has-attr.3F"><h3>has-attr?</h3><div class="usage"><code>(has-attr? pyobj att-name)</code></div><div class="doc"><div class="markdown"><p>Return true if this python object has this attribute.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L218">view source</a></div></div><div class="public anchor" id="var-has-item.3F"><h3>has-item?</h3><div class="usage"><code>(has-item? pyobj item-name)</code></div><div class="doc"><div class="markdown"><p>Return true if the python object has an item. Calls <strong>hasitem</strong>.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L237">view source</a></div></div><div class="public anchor" id="var-import-as"><h3>import-as</h3><h4 class="type">macro</h4><div class="usage"><code>(import-as module-path varname)</code></div><div class="doc"><div class="markdown"><p>Import a module and assign it to a var. Documentation is included.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L292">view source</a></div></div><div class="public anchor" id="var-import-module"><h3>import-module</h3><div class="usage"><code>(import-module modname)</code></div><div class="doc"><div class="markdown"><p>Import a python module. Module entries can be accessed via get-attr.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L154">view source</a></div></div><div class="public anchor" id="var-initialize.21"><h3>initialize!</h3><div class="usage"><code>(initialize! & {:keys [windows-anaconda-activate-bat library-path no-io-redirect?], :as options})</code></div><div class="doc"><div class="markdown"><p>Initialize the python library. If library path is not provided, then the system attempts to execute a simple python program and have python return system info.</p>
<p>Returns either <code>:ok</code> in which case the initialization completed successfully or <code>:already-initialized</code> in which case we detected that python has already been initialized via <code>Py_IsInitialized</code> and we do nothing more.</p>
<p>Options:</p>
<ul>
<li><code>:library-path</code> - Library path of the python library to use.</li>
<li><code>:program-name</code> - Optional – will show up in error messages from python.</li>
<li><code>:no-io-redirect?</code> - True if you don’t want python stdout and stderr redirection to <em>out</em> and <em>err</em>.</li>
<li><code>:python-executable</code> - The python executable to use to find system information.</li>
<li><code>:python-home</code> - Python home directory. The system first uses this variable, then the environment variable PYTHON_HOME, and finally information returned from python system info.</li>
<li><code>:signals?</code> - defaults to false - true if you want python to initialized signals. Be aware that the JVM itself uses quite a few signals - SIGSEGV, for instance - during it’s normal course of operation. For more information see:
<ul>
<li><a href="https://docs.oracle.com/javase/10/troubleshoot/handle-signals-and-exceptions.htm#JSTGD356">used signals</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/vm/signal-chaining.html">signal-chaining</a></li>
</ul>
</li>
</ul></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L46">view source</a></div></div><div class="public anchor" id="var-is-instance.3F"><h3>is-instance?</h3><div class="usage"><code>(is-instance? py-inst py-cls)</code></div><div class="doc"><div class="markdown"><p>Return true if inst is an instance of cls. Note that arguments are reversed as compared to <code>instance?</code></p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L315">view source</a></div></div><div class="public anchor" id="var-make-callable"><h3>make-callable</h3><div class="usage"><code>(make-callable ifn options)</code><code>(make-callable ifn)</code></div><div class="doc"><div class="markdown"><p>Make a python callable object from a clojure function. This is called for you if you use <code>as-python</code> on an implementation of IFn.</p>
<p>Options: * <code>:arg-converter</code> - Function called for each function argument before your ifn gets access to it. Defaults to <code>->jvm</code>. * <code>:result-converter</code> - Function called on return value before it gets returned to python. Must return a python object. Defaults to <code>->python</code>; the result will get an extra incref before being returned to Python to account for the implied tracking of <code>as-python</code> or <code>->python</code>. * <code>:name</code> - Name of the python method. This will appear in stack traces. * <code>:doc</code> - documentation for method.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L395">view source</a></div></div><div class="public anchor" id="var-make-instance-fn"><h3>make-instance-fn</h3><div class="usage"><code>(make-instance-fn ifn options)</code><code>(make-instance-fn ifn)</code></div><div class="doc"><div class="markdown"><p>Make an callable instance function - a function which will be passed the ‘this’ object as it’s first argument. In addition, this function calls <code>make-callable</code> with a <code>arg-converter</code> defaulted to <code>as-jvm</code>. See documentation for [[libpython-clj2.python.class/make-instance-fn.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L419">view source</a></div></div><div class="public anchor" id="var-make-kw-instance-fn"><h3>make-kw-instance-fn</h3><div class="usage"><code>(make-kw-instance-fn ifn options)</code><code>(make-kw-instance-fn ifn)</code></div><div class="doc"><div class="markdown"><p>Make an kw callable instance function - function by default is passed 2 arguments, the positional argument vector and a map of keyword arguments. Results are marshalled back to python using <a href="null">libpython-clj2.python.fn/bridged-fn-arg->python</a> which is also used when bridging an object into python. See documentation for <a href="null">libpython-clj2.python.class/make-kw-instance-fn</a>.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L428">view source</a></div></div><div class="public anchor" id="var-module-dict"><h3>module-dict</h3><div class="usage"><code>(module-dict mod)</code></div><div class="doc"><div class="markdown"><p>Get the module dictionary.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L173">view source</a></div></div><div class="public anchor" id="var-path-.3Epy-obj"><h3>path->py-obj</h3><div class="usage"><code>(path->py-obj item-path & {:keys [reload?]})</code></div><div class="doc"><div class="markdown"><p>Given a string such as “builtins” or “builtins.list”, load the module or the class object in the module.</p>
<p>Options:</p>
<ul>
<li><code>:reload</code> - Reload the module.</li>
</ul></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L657">view source</a></div></div><div class="public anchor" id="var-py*"><h3>py*</h3><h4 class="type">macro</h4><div class="usage"><code>(py* x method args)</code><code>(py* x method args kwargs)</code></div><div class="doc"><div class="markdown"><p>Special syntax for passing along *args and **kwargs style arguments to methods.</p>
<p>Usage:</p>
<p>(py* obj method args kwargs)</p>
<p>Example:</p>
<p>(def d (python/dict)) d ;;=> {} (def iterable <a href="null">:a 1] [:b 2</a>) (def kwargs {:cat “dog” :name “taco”}) (py* d update [iterable] kwargs) d ;;=> {“a”: 1, “b”: 2, “cat”: “dog”, “name”: “taco”}</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L546">view source</a></div></div><div class="public anchor" id="var-py**"><h3>py**</h3><h4 class="type">macro</h4><div class="usage"><code>(py** x method kwargs)</code><code>(py** x method arg & args)</code></div><div class="doc"><div class="markdown"><p>Like py*, but it is assumed that the LAST argument is kwargs.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L568">view source</a></div></div><div class="public anchor" id="var-py."><h3>py.</h3><h4 class="type">macro</h4><div class="usage"><code>(py. x method-name & args)</code></div><div class="doc"><div class="markdown"><p>Class/object method syntax. (py. obj method arg1 arg2 … argN) is equivalent to Python’s obj.method(arg1, arg2, …, argN) syntax.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L537">view source</a></div></div><div class="public anchor" id="var-py.-"><h3>py.-</h3><h4 class="type">macro</h4><div class="usage"><code>(py.- x arg)</code></div><div class="doc"><div class="markdown"><p>Class/object getter syntax. (py.- obj attr) is equivalent to Python’s obj.attr syntax.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L530">view source</a></div></div><div class="public anchor" id="var-py.."><h3>py..</h3><h4 class="type">macro</h4><div class="usage"><code>(py.. x & args)</code></div><div class="doc"><div class="markdown"><p>Extended accessor notation, similar to the <code>..</code> macro in Clojure.</p>
<p>(require-python ’sys) (py.. sys -path (append “/home/user/bin”))</p>
<p>is equivalent to Python’s</p>
<p>import sys sys.path.append(‘/home/user/bin’)</p>
<p>SPECIAL SYNTAX for programmatic *args and **kwargs</p>
<p>Special syntax is provided to meet the needs required by Python’s *args and **kwargs syntax programmatically.</p>
<p>(= (py.. obj (*method args)) (py* obj methods args))</p>
<p>(= (py.. obj (*method args kwargs)) (py* obj method args kwargs))</p>
<p>(= (py.. obj (**method kwargs)) (py** obj method kwargs))</p>
<p>(= (py.. obj (**method arg1 arg2 arg3 … argN kwargs)) (py** obj method arg1 arg2 arg3 … argN kwargs) (py* obj method [arg1 arg2 arg3 … argN] kwargs))</p>
<p>These forms exist for when you need to pass in a map of options in the same way you would use the f(*args, **kwargs) forms in Python.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L603">view source</a></div></div><div class="public anchor" id="var-python-type"><h3>python-type</h3><div class="usage"><code>(python-type v)</code></div><div class="doc"><div class="markdown"><p>Get the type (as a keyword) of a python object</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L286">view source</a></div></div><div class="public anchor" id="var-run-simple-string"><h3>run-simple-string</h3><div class="usage"><code>(run-simple-string program & {:keys [globals locals]})</code></div><div class="doc"><div class="markdown"><p>Run a string expression returning a map of {:globals :locals}. This uses the global <strong>main</strong> dict under the covers so it matches the behavior of the cpython implementation with the exception of returning the various maps used.</p>
<p>Note this will never return the result of the expression: <a href="https://mail.python.org/pipermail/python-list/1999-April/018011.html">https://mail.python.org/pipermail/python-list/1999-April/018011.html</a></p>
<p>Globals, locals may be provided but are not necessary.</p>
<p>Implemented in cpython as:</p>
<p>PyObject *m, *d, *v; m = PyImport_AddModule(“<strong>main</strong>”); if (m == NULL) return -1; d = PyModule_GetDict(m); v = PyRun_StringFlags(command, Py_file_input, d, d, flags); if (v == NULL) { PyErr_Print(); return -1; } Py_DECREF(v); return 0;</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L362">view source</a></div></div><div class="public anchor" id="var-set-attr.21"><h3>set-attr!</h3><div class="usage"><code>(set-attr! pyobj attname attval)</code></div><div class="doc"><div class="markdown"><p>Set an attribute on a python object. Returns pyobj.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L204">view source</a></div></div><div class="public anchor" id="var-set-attrs.21"><h3>set-attrs!</h3><div class="usage"><code>(set-attrs! pyobj att-seq)</code></div><div class="doc"><div class="markdown"><p>Set a sequence of [name value] attributes. Returns pyobj.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L211">view source</a></div></div><div class="public anchor" id="var-set-item.21"><h3>set-item!</h3><div class="usage"><code>(set-item! pyobj item-name item-val)</code></div><div class="doc"><div class="markdown"><p>Get an item from a python object using <strong>setitem</strong></p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L230">view source</a></div></div><div class="public anchor" id="var-set-items.21"><h3>set-items!</h3><div class="usage"><code>(set-items! pyobj item-seq)</code></div><div class="doc"><div class="markdown"><p>Set a sequence of [name value]. Returns pyobj</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L243">view source</a></div></div><div class="public anchor" id="var-stack-resource-context"><h3>stack-resource-context</h3><h4 class="type">macro</h4><div class="usage"><code>(stack-resource-context & body)</code></div><div class="doc"><div class="markdown"><p>Create a stack-based resource context. All python objects allocated within this context will be released at the termination of this context. !!This means that no python objects can escape from this context!! You must use copy semantics (->jvm) for anything escaping this context. Furthermore, if you are returning generic python objects you may need to call (into {}) or something like that just to ensure that absolutely everything is copied into the jvm.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L110">view source</a></div></div><div class="public anchor" id="var-with"><h3>with</h3><h4 class="type">macro</h4><div class="usage"><code>(with bind-vec & body)</code></div><div class="doc"><div class="markdown"><p>Support for the ‘with’ statement in python: (py/with [item (py/call-attr testcode-module “WithObjClass” true fn-list)] (py/call-attr item “doit_err”))</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L501">view source</a></div></div><div class="public anchor" id="var-with-gil"><h3>with-gil</h3><h4 class="type">macro</h4><div class="usage"><code>(with-gil & body)</code></div><div class="doc"><div class="markdown"><p>Capture the gil for an extended amount of time. This can greatly speed up operations as the mutex is captured and held once as opposed to find grained grabbing/releasing of the mutex.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L123">view source</a></div></div><div class="public anchor" id="var-with-gil-stack-rc-context"><h3>with-gil-stack-rc-context</h3><h4 class="type">macro</h4><div class="usage"><code>(with-gil-stack-rc-context & body)</code></div><div class="doc"><div class="markdown"><p>Capture the gil, open a resource context. The resource context is released before the gil is leading to much faster resource collection. See documentation on <code>stack-resource-context</code> for multiple warnings; the most important one being that if a python object escapes this context your program will eventually, at some undefined point in the future crash. That being said, this is the recommended pathway to use in production contexts where you want defined behavior and timings related to use of python.</p></div></div><div class="src-link"><a href="https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj2/python.clj#L132">view source</a></div></div></div></body></html>