You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python client API for LabKey Server. To get started, please see the [full documentation for this library](https://www.labkey.org/wiki/home/Documentation/page.view?name=python).
2
+
The Python client API for LabKey Server lets you query, insert and update data on a LabKey Server from a Python client.
3
+
4
+
# Release Notes
5
+
6
+
Changes in the current release:
7
+
8
+
- Support for Python 3
9
+
- Support for netrc files (.labkeycredentials.txt files are now deprecated)
- PEP standards - the latest version follows PEP code styling standards
15
+
- New [samples](https://github.com/LabKey/labkey-api-python/tree/master/samples)
3
16
4
17
# Installation
5
18
To install, simply use `pip`:
@@ -9,27 +22,71 @@ $ pip install labkey
9
22
```
10
23
11
24
# Credentials
12
-
In order to the use the Python client API for LabKey Server, you will need to specify your login credentials in a credential file. The package assumes that this file will be located either:
25
+
As of v0.4.0 this API no longer supports using a ``.labkeycredentials.txt`` file, and now uses the .netrc files similar to the other labkey APIs. Additional .netrc [setup instructions](https://www.labkey.org/wiki/home/Documentation/page.view?name=netrc) can be found at the link.
26
+
27
+
## Set Up a netrc File
28
+
29
+
On a Mac, UNIX, or Linux system the netrc file should be named ``.netrc`` (dot netrc) and on Windows it should be named ``_netrc`` (underscore netrc). The file should be located in your home directory and the permissions on the file must be set so that you are the only user who can read it, i.e. it is unreadable to everyone else.
13
30
14
-
1.``$HOME/.labkeycredentials.txt``
15
-
2. The location will be specified in the ``LABKEY_CREDENTIALS`` environment variable.
31
+
To create the netrc on a Windows machine, first create an environment variable called ’HOME’ that is set to your home directory (for example, C:/Users/johndoe) or any directory you want to use.
32
+
33
+
In that directory, create a text file with the prefix appropriate to your system, either an underscore or dot.
34
+
35
+
The following three lines must be included in the file. The lines must be separated by either white space (spaces, tabs, or newlines) or commas:
36
+
```
37
+
machine <remote-instance-of-labkey-server>
38
+
login <user-email>
39
+
password <user-password>
40
+
```
16
41
17
-
The ``labkeycredentials`` file must be in the following format. (3 separate lines):
42
+
For example:
18
43
```
19
-
machine https://hosted.labkey.com
20
-
login labkeypython@gmail.com
21
-
password python
44
+
machine mymachine.labkey.org
45
+
login user@labkey.org
46
+
password mypassword
22
47
```
23
-
where:
24
-
- machine: URL of your LabKey Server
25
-
- login: email address to be used to login to the LabKey Server
26
-
- password: password associated with the login
48
+
Note that the netrc file only deals with connections at the machine level and should not include a port or protocol designation, meaning both "mymachine.labkey.org:8888" and "https://mymachine.labkey.org" are incorrect.
27
49
28
-
A sample ``labkeycredentials`` file has been shipped with the source and named ``.labkeycredentials.sample``.
50
+
# Supported Functions
51
+
52
+
-**labkey.query.select_rows()** - Query and get results sets from LabKey Server.
53
+
-**labkey.query.execute_sql()** - Execute SQL (LabKey SQL dialect) through the query module on LabKey Server.
54
+
-**labkey.query.insert_rows()** - Insert rows into a table on LabKey Server.
55
+
-**labkey.query.update_rows()** - Update rows in a table on LabKey Server.
56
+
-**labkey.query.delete_rows()** - Delete records in a table on LabKey Server.
57
+
-**labkey.experiment.load_batch()** - Retreive assay data (batch level) from LabKey Server.
58
+
-**labkey.experiment.save_batch()** - Save assay data (batch level) on LabKey Server.
59
+
60
+
# Examples
61
+
62
+
Sample code is available in the [samples](https://github.com/LabKey/labkey-api-python/tree/experiment/samples) directory.
63
+
64
+
The following gets data from the Users table on your local machine:
65
+
66
+
```python
67
+
from labkey.utils import create_server_context
68
+
from labkey.query import select_rows
69
+
70
+
print("Create a server context")
71
+
labkey_server ='localhost:8080'
72
+
project_name ='ModuleAssayTest'# Project folder name
result = select_rows(server_context, schema, table)
80
+
if result isnotNone:
81
+
print(result['rows'][0])
82
+
print("select_rows: Number of rows returned: "+str(result['rowCount']))
83
+
else:
84
+
print('select_rows: Failed to load results from '+ schema +'.'+ table)
85
+
```
29
86
30
87
# Supported Versions
31
-
Python 2.6 or 2.7 are fully supported.
32
-
LabKey Server v11.1 and later.
88
+
Python 2.6+ and 3.4+ are fully supported.
89
+
LabKey Server v13.3 and later.
33
90
34
91
# Contributing
35
92
This library and the LabKey Server are maintained by the LabKey Software Foundation. If you have any questions or need support, please use the [LabKey Server support forum](https://www.labkey.org/wiki/home/page.view?name=support).
0 commit comments