Skip to content

Commit eba7bc9

Browse files
committed
init
0 parents  commit eba7bc9

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# elabapi-python
2+
3+
Python library to interact with [eLabFTW](https://github.com/elabftw/elabftw) REST API v2.
4+
5+
## Generate
6+
docker run --rm -v /home/ktr/.dev/elabapi-python:/local swaggerapi/swagger-codegen-cli-v3 generate -i https://raw.githubusercontent.com/elabftw/elabftw/hypernext/apidoc/v2/openapi.yaml -l python -o /local/generated

config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"packageName": "elabapi_python",
3+
"projectName": "elabapi-python",
4+
"packageVersion": "0.1.0",
5+
"packageUrl": "https://github.com/elabftw/elabapi-python"
6+
}

examples/00.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
import time
3+
import elabapi_python
4+
from elabapi_python.rest import ApiException
5+
6+
# replace with your api key
7+
my_api_key = 'apiKey4Test'
8+
9+
# Config
10+
configuration = elabapi_python.Configuration()
11+
configuration.api_key['api_key'] = my_api_key
12+
configuration.api_key_prefix['api_key'] = 'Authorization'
13+
configuration.host = 'https://elab.local:3148/api/v2'
14+
configuration.debug = True
15+
configuration.verify_ssl = False
16+
17+
# create an instance of the API class
18+
api_client = elabapi_python.ApiClient(configuration)
19+
# fix issue with Authorization header not being properly set by the generated lib
20+
api_client.set_default_header(header_name='Authorization', header_value='apiKey4Test')
21+
22+
# create an instance of Items
23+
items = elabapi_python.ItemsApi(api_client)
24+
print(items.read_items())

helper.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# This script will generate a python library from the openapi definition file.
3+
4+
# the docker image used to generate the client code
5+
docker_image="swaggerapi/swagger-codegen-cli-v3"
6+
# where to grab the definition file
7+
openapi_yaml_url="https://raw.githubusercontent.com/elabftw/elabftw/hypernext/apidoc/v2/openapi.yaml"
8+
# folder with the generated python code
9+
lib="generated"
10+
11+
function generate {
12+
# clean up first
13+
rm -rfv "$lib"
14+
# now generate the lib
15+
docker run --user "$(id -u)":"$(id -gn)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
16+
}
17+
18+
function build {
19+
cd "$lib" || exit 1
20+
python setup.py sdist bdist_egg bdist_wheel
21+
cd ..
22+
}
23+
24+
function publish {
25+
build
26+
cd "$lib" || exit 1
27+
twine upload dist/*
28+
cd ..
29+
}
30+
31+
"$1"

0 commit comments

Comments
 (0)