This is the py4cl Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:21:52 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
py4cl
Call Python libraries from Common Lisp
Ben Dudson <benjamin.dudson@york.ac.uk>
MIT
trivial-garbage
(system).
uiop
(system).
cl-json
(system).
numpy-file-format
(system).
package.lisp
(file).
config.lisp
(file).
reader.lisp
(file).
writer.lisp
(file).
python-process.lisp
(file).
lisp-classes.lisp
(file).
callpython.lisp
(file).
import-export.lisp
(file).
do-after-load.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
py4cl/py4cl.asd
py4cl/package.lisp
py4cl/config.lisp
py4cl/reader.lisp
py4cl/writer.lisp
py4cl/python-process.lisp
py4cl/lisp-classes.lisp
py4cl/callpython.lisp
py4cl/import-export.lisp
py4cl/do-after-load.lisp
py4cl/py4cl.asd
py4cl
(system).
*base-directory*
(special variable).
py4cl/config.lisp
package.lisp
(file).
py4cl
(system).
*config*
(special variable).
config-var
(function).
(setf config-var)
(function).
initialize
(function).
load-config
(function).
py-cd
(function).
save-config
(function).
take-input
(function).
py4cl/reader.lisp
config.lisp
(file).
py4cl
(system).
*freed-python-objects*
(special variable).
copy-python-object
(function).
delete-freed-python-objects
(function).
delete-numpy-pickle-arrays
(function).
free-python-object
(function).
make-python-object
(function).
make-python-object-finalize
(function).
python-object
(structure).
python-object-handle
(reader).
(setf python-object-handle)
(writer).
python-object-p
(function).
python-object-type
(reader).
(setf python-object-type)
(writer).
stream-read-string
(function).
stream-read-value
(function).
py4cl/writer.lisp
reader.lisp
(file).
py4cl
(system).
*handle-counter*
(special variable).
*lisp-objects*
(special variable).
*numpy-pickle-index*
(special variable).
clear-lisp-objects
(function).
free-handle
(function).
lisp-object
(function).
object-handle
(function).
pythonize
(generic function).
stream-write-string
(function).
stream-write-value
(function).
py4cl/python-process.lisp
writer.lisp
(file).
py4cl
(system).
*python-command*
(special variable).
python-alive-p
(function).
python-interrupt
(function).
python-start
(function).
python-start-if-not-alive
(function).
python-stop
(function).
python-version-info
(function).
*current-python-process-id*
(special variable).
*py4cl-tests*
(special variable).
*python*
(special variable).
py4cl/lisp-classes.lisp
python-process.lisp
(file).
py4cl
(system).
python-getattr
(generic function).
python-setattr
(generic function).
py4cl/callpython.lisp
lisp-classes.lisp
(file).
py4cl
(system).
chain
(macro).
python-call
(function).
python-call-async
(function).
python-error
(condition).
python-eval
(function).
(setf python-eval)
(function).
python-exec
(function).
python-generator
(function).
python-method
(function).
python-setf
(function).
remote-objects
(macro).
remote-objects*
(macro).
dispatch-messages
(function).
dispatch-reply
(function).
function-args
(function).
python-eval*
(function).
text
(reader method).
py4cl/import-export.lisp
callpython.lisp
(file).
py4cl
(system).
export-function
(function).
import-function
(macro).
import-module
(macro).
py4cl/do-after-load.lisp
import-export.lisp
(file).
py4cl
(system).
Packages are listed by definition order.
py4cl
common-lisp
.
*config*
(special variable).
*python-command*
(special variable).
chain
(macro).
config-var
(function).
(setf config-var)
(function).
export-function
(function).
import-function
(macro).
import-module
(macro).
initialize
(function).
load-config
(function).
py-cd
(function).
python-alive-p
(function).
python-call
(function).
python-call-async
(function).
python-error
(condition).
python-eval
(function).
(setf python-eval)
(function).
python-exec
(function).
python-generator
(function).
python-getattr
(generic function).
python-interrupt
(function).
python-method
(function).
python-setattr
(generic function).
python-setf
(function).
python-start
(function).
python-start-if-not-alive
(function).
python-stop
(function).
python-version-info
(function).
remote-objects
(macro).
remote-objects*
(macro).
save-config
(function).
*current-python-process-id*
(special variable).
*freed-python-objects*
(special variable).
*handle-counter*
(special variable).
*lisp-objects*
(special variable).
*numpy-pickle-index*
(special variable).
*py4cl-tests*
(special variable).
*python*
(special variable).
clear-lisp-objects
(function).
copy-python-object
(function).
delete-freed-python-objects
(function).
delete-numpy-pickle-arrays
(function).
dispatch-messages
(function).
dispatch-reply
(function).
free-handle
(function).
free-python-object
(function).
function-args
(function).
lisp-object
(function).
make-python-object
(function).
make-python-object-finalize
(function).
object-handle
(function).
python-eval*
(function).
python-object
(structure).
python-object-handle
(reader).
(setf python-object-handle)
(writer).
python-object-p
(function).
python-object-type
(reader).
(setf python-object-type)
(writer).
pythonize
(generic function).
stream-read-string
(function).
stream-read-value
(function).
stream-write-string
(function).
stream-write-value
(function).
take-input
(function).
text
(generic reader).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Used for storing configuration at a centralized location.
String, the Python executable to launch e.g. "python" or "python3"
Chain method calls, member access, and indexing operations
on objects. The operations in CHAIN are applied in order from
first to last to the TARGET object.
TARGET can be
cons – a python function to call, returning an object to operate on
otherwise – a value, to be converted to a python value
CHAIN can consist of
cons – a method to call
symbol – a member data variable
otherwise – a value put between [] brackets to access an index
Keywords inside python function calls are converted to python keywords.
Functions can be specified using a symbol or a string. If a symbol is used
then it is converted to python using STRING-DOWNCASE.
Examples:
(chain "hello {0}" (format "world") (capitalize))
=> python: "hello {0}".format("world").capitalize()
=> "Hello world"
(chain (range 3) stop)
=> python: range(3).stop
=> 3
(chain "hello" 4)
=> python: "hello"[4]
=> "o"
Define a function which calls python
Example
(py4cl:python-exec "import math")
(py4cl:import-function "math.sqrt")
(math.sqrt 42)
-> 6.4807405
Keywords:
AS specifies the symbol to be used in Lisp. This can be a symbol
or a string. If a string is given then it is read using READ-FROM-STRING.
DOCSTRING is a string which becomes the function docstring
FROM specifies a module to load the function from. This will cause the python module to be imported into the python session.
Import a python module as a Lisp package. The module name should be
a string.
Example:
(py4cl:import-module "math")
(math:sqrt 4) ; => 2.0
or using
Keywords:
AS specifies the name to be used for both the Lisp package and python module.
It should be a string, and if not supplied then the module name is used.
RELOAD specifies that the package should be deleted and reloaded.
By default if the package already exists then a string is returned.
Ensures that all values returned by python functions
and methods are kept in python, and only handles returned to lisp.
This is useful if performing operations on large datasets.
Ensures that all values returned by python functions
and methods are kept in python, and only handles returned to lisp.
This is useful if performing operations on large datasets.
This version evaluates the result, returning it as a lisp value if possible.
Makes a lisp FUNCTION available in python process as PYTHON-NAME
Intended to be called first upon installation. Sets up default python command, and numpy pickle file and lower bounds.
Returns non-NIL if the python process is alive
(e.g. SBCL -> T, CCL -> RUNNING).
Optionally pass the process object returned by PYTHON-START
Call a python function, given the function name as a string
and additional arguments. Keywords are converted to keyword arguments.
Call a python function asynchronously.
Returns a lambda which when called returns the result.
Evaluate an expression in python, returning the result
Arguments ARGS can be strings, or other objects. Anything which
is not a string is converted to a python value
Examples:
(python-eval "[i**2 for i in range(" 4 ")]") => #(0 1 4 9)
(let ((a 10) (b 2))
(py4cl:python-eval a
Set an expression to a value. Just adds "=" and the value
to the end of the expression. Note that the result is evaluated
with exec rather than eval.
Examples:
(setf (python-eval "a") 2) ; python "a=2"
Execute (using exec) an expression in python. This is used for statements rather than expressions.
Call a given method on an object OBJ. METHOD-NAME can be a
symbol (converted to lower case) or a string.
Examples:
(python-method "hello {0}" ’format "world")
; => "hello world"
(python-method ’(1 2 3) ’__len__)
; => 3
Set python variables in ARGS ("var1" value1 "var2" value2 ...)
Start a new python subprocess
This sets the global variable *python* to the process handle,
in addition to returning it.
COMMAND is a string with the python executable to launch e.g. "python"
By default this is is set to *PYTHON-COMMAND*
If no python process is running, tries to start it. If still not alive, raises a condition.
Return a list, using the result of python’s sys.version_info.
A number which changes when python is started. This
is used to prevent garbage collection from deleting objects in the wrong
python session
A list of handles to be freed. This is used because garbage collection may occur in parallel with the main thread.
Used for transferring multiple numpy-pickled arrays in one pyeval/exec/etc
Set nil for something like py4cl/tests::interrupt test, for unknown reasons.
Most recently started python subprocess
Clear the *lisp-objects* object store, allowing them to be GC’d
Delete pickled arrays, to free space.
Read response from python, loop to handle any callbacks
Remove an object with HANDLE from the hash table
Internal function, intended to be called by the CHAIN macro.
Converts function arguments to a list of strings and (pythonize )
function calls. Handles keywords and insertion of commas.
Returns a list which can be passed to PYTHON-EVAL.
Examples:
(py4cl::function-args ’(1 :test 2))
=> ((PY4CL::PYTHONIZE 1) "," "test" "=" (PY4CL::PYTHONIZE 2))
Get the lisp object corresponding to HANDLE
Make a PYTHON-OBJECT struct with a finalizer.
This deletes the object from the dict store in python.
Uses trivial-garbage (public domain)
Store OBJECT and return a handle
Internal function, which converts ARGS into a string to be evaluated
This handles both EVAL and EXEC calls with CMD-CHAR being different
in the two cases.
Anything in ARGS which is not a string is passed through PYTHONIZE
type
.
Reads a string from a stream
Expects a line containing the number of chars following
e.g. ’5~%hello’
Returns the string or nil on error
Get a value from a stream
Currently works by reading a string then using read-from-string
Write a string to a stream, putting the length first
Write a value to a stream, in a format which can be read by the python subprocess as the corresponding python type
Convert an object into a string which can be written to stream. Default implementation creates a handle to an unknown Lisp object.
ratio
)) ¶Handle ratios, using Python’s Fraction if available
python-object
)) ¶A handle for a python object, stored in a dict in Python
function
)) ¶Handle a function by converting to a callback object
The lisp function is stored in the same object store as other objects.
hash-table
)) ¶Convert hash-table to python map. Produces a string {key1:value1, key2:value2,}
symbol
)) ¶Handle symbols. Need to handle NIL,
converting it to Python None, and convert T to True.
string
)) ¶cons
)) ¶Convert a list. This leaves a trailing comma so that python evals a list with a single element as a tuple
array
)) ¶complex
)) ¶Create string of the form "(1+2j".
If imaginary part is negative the output is of form "(1+-2j"
which is interpreted correctly by python (3.7.2).
real
)) ¶Write a real number.
Note that python doesn’t handle ’d’,’f’, ’s’ or ’L’ exponent markers
python-error
)) ¶text
.
A handle for a python object
which couldn’t be translated into a Lisp value.
TYPE slot is the python type string
HANDLE slot is a unique key used to refer to a value in python.
Jump to: | (
C D E F G I L M O P R S T |
---|
Jump to: | (
C D E F G I L M O P R S T |
---|
Jump to: | *
H S T |
---|
Jump to: | *
H S T |
---|
Jump to: | C D F I L P R S W |
---|
Jump to: | C D F I L P R S W |
---|