Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
64506064
Commit
64506064
authored
11 years ago
by
ocelot-inc
Browse files
Options
Downloads
Patches
Plain Diff
connectors.xml revise python example
parent
01c70467
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/user/connectors.xml
+13
-15
13 additions, 15 deletions
doc/user/connectors.xml
with
13 additions
and
15 deletions
doc/user/connectors.xml
+
13
−
15
View file @
64506064
...
...
@@ -350,33 +350,31 @@ catch (Exception $e) {
<section
xml:id=
"connector-python"
>
<title>
Python
</title>
<para>
Here is a complete Python program that inserts ['A','BB'] into space[0] via the high-level Python API.
To prepare, paste the code into a file named example.py and say:
<code>
export PYTHONPATH=
<replaceable>
tarantool-directory
</replaceable>
/test/lib
</code>
where
<replaceable>
tarantool-directory
</replaceable>
/test/lib = the directory that contains
the necessary file
<filename>
box_connection.py
</filename>
. This will be
the directory where Tarantool Python library files were placed at installation time
for a source download.
Here is a complete Python program that inserts [99999,'BB'] into space[0] via the high-level Python API.
To prepare, paste the code into a file named example.py and install tarantool-python with either
<userinput><code>
pip install tarantool
</code></userinput>
to install in
<filename>
/usr
</filename>
(requires root privilege)
or
<userinput><code>
pip install tarantool --user
</code></userinput>
to install in
<filename>
~
</filename>
i.e. user's default directory.
Before trying to run, check that the server (tarantool_box) is running on localhost (127.0.0.1) and its primary port
is the default (33013) and space[0]'s primary key type is string (space[0].index[0].key_field[0].type = "STR" in configuration file).
To run, say
<code>
python example.py
</code>
.
The program will connect to the server, send the request, and
display
<quote>
Insert OK, 1 row affected
</quote>
if all went well.
If the row already exists, the program will
print
<quote>
Duplicate key exists in unique index 0
</quote>
.
The program will connect to the server,
will
send the request, and
will not throw an exception
if all went well.
If the row already exists, the program will
throw DatabaseException(“
Duplicate key exists in unique index 0
”)
.
</para>
<programlisting
language=
"python"
>
#!/usr/bin/python
from
box_connection
import
Box
Connection
from
tarantool
import Connection
c =
Box
Connection("127.0.0.1", 33013)
result = c.
execute("INSERT INTO t0 VALUES ('A'
,'BB')
"
)
c = Connection("127.0.0.1", 33013)
result = c.
insert(0,(99999
,'BB'))
print result
</programlisting>
<para>
The example program only shows one command and does not show all that's necessary for
good practice. For that, please see
<link
xlink:href=
"https://github.com/mailru/tarantool-python"
><filename>
http://github.com/mailru/tarantool-python
</filename></link>
and
<link
xlink:href=
"https://github.com/zlobspb/txtarantool"
><filename>
https://github.com/zlobspb/txtarantool
</filename></link>
.
<link
xlink:href=
"http://tarantool-python.readthedocs.org/en/latest/"
><filename>
http://tarantool-python.readthedocs.org/en/latest/
</filename></link>
.
For an example of a Python API for
<link
xlink:href=
"https://github.com/tarantool/queue"
>
Queue managers on Tarantool
</link>
, see
<link
xlink:href=
"https://github.com/tarantool/tarantool-queue-python"
><filename>
https://github.com/tarantool/tarantool-queue-python
</filename></link>
.
</para>
</section>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment