Skip to content

Commit

Permalink
release 3.1.0
Browse files Browse the repository at this point in the history
- support for SSL verification
- support for proxies
  • Loading branch information
Andrea Pierleoni committed Dec 22, 2017
1 parent a1fed66 commit baf7267
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# opentargets-py
Python client for the Open Targets REST API at targetvalidation.org
Python client for the Open Targets REST API at api.opentargets.io
[![Build Status](https://travis-ci.org/opentargets/opentargets-py.svg?branch=master)](https://travis-ci.org/opentargets/opentargets-py)
[![Documentation Status](https://readthedocs.org/projects/opentargets/badge/?version=latest)](http://opentargets.readthedocs.io/en/latest/?badge=latest)

Expand All @@ -13,6 +13,7 @@ Why should you use this client instead of the REST API directly?
- Handles fair usage limits transparently
- Follows HTTP cache as set by the REST API
- Experimental HTTP2 support for better performance (beware the client library is in alpha)
- Support for advanced SSL and proxy configuration

This client is supported for Python 3.5 and upper.
Works on pythoon 2.7 on a best effort basis.
Expand Down Expand Up @@ -64,7 +65,7 @@ virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
```
## How to contribute:
## How to contribute:
1. (if you are not part of the open targets team) fork the repo
2. branch from master, always start with `git checkout -b yourname-featureyouareadding`
2. code
Expand All @@ -78,4 +79,4 @@ pip install -r requirements.txt
2. add a tag using semantic versioning, pointing to `master`
3. Press publish

Releases will automatically deploy to pypi (thanks to travis) once they are created in the github console.
Releases will automatically deploy to pypi (thanks to travis) once they are created in the github console.
5 changes: 5 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Changelog
=========

3.1.0
-----
- added SSL ceritificate customisation
- added HTTP and SOCKS proxies support

3.0.0
-----
Compatible with REST API release 3.0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
opentargets - Python client for targetvalidation.org
====================================================

**opentargets** is the official python client for the `Open Targets REST API`_ at `targetvalidation.org`_
**opentargets** is the official python client for the `Open Targets REST API`_ at `api.opentargets.io`_

This client allows you to query the API automatically taking care of handling all
the calls and returning data in a pythonic way.
Expand Down
19 changes: 18 additions & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import the high level client

from opentargets import OpenTargetsClient
ot = OpenTargetsClient()

or if you have an API key
::

Expand Down Expand Up @@ -159,5 +159,22 @@ If you want to change the way the associations are scored using just some dataty
(1.6803112925534462, 'EFO_0000228', {'genetic_association': 1.0, 'known_drug': 0.9357799925142999, 'somatic_mutation': 0.6372638888888889})
(1.6013073034769463, 'EFO_0000512', {'genetic_association': 1.0, 'known_drug': 1.0, 'somatic_mutation': 0.303921910430839})

Using insecure SSL? local certificate? an HTTP or SOCKS proxy?
::

>>> from opentargets import OpenTargetsClient
>>> from opentargets.statistics import HarmonicSumScorer
>>> ot = OpenTargetsClient(verify = False) # SSL not verified
>>> ot = OpenTargetsClient(verify = 'path to my certificate') # local certificate
>>> ot = OpenTargetsClient(proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}) # HTTP proxies
>>> ot = OpenTargetsClient(proxies = {
'http': 'socks5://user:pass@host:port',
'https': 'socks5://user:pass@host:port'
}) # HTTP proxies

verify and proxies options works as in the (requests library)[http://docs.python-requests.org/en/master/user/advanced/]


13 changes: 9 additions & 4 deletions opentargets/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def __init__(self,
auth_app_name = None,
auth_secret = None,
use_http2=False,
verify = True,
proxies = {}
):
"""
Args:
Expand All @@ -204,6 +206,7 @@ def __init__(self,
auth_app_name (str): app_name if using authentication
auth_secret (str): secret if using authentication
use_http2 (bool): use http2 client
verify (bool): sets SSL verification for Request session, accepts True, False or a path to a certificate
"""
self._logger = logging.getLogger(__name__)
self.host = host
Expand All @@ -218,10 +221,12 @@ def __init__(self,
self.token = None
self.use_http2 = use_http2
session= requests.Session()
retry_policies = Retry(total=5,
read=5,
connect=5,
backoff_factor=.2,
session.verify = verify
session.proxies = proxies
retry_policies = Retry(total=10,
read=10,
connect=10,
backoff_factor=.5,
status_forcelist=(500, 502, 504),)
http_retry = HTTPAdapter(max_retries=retry_policies)
session.mount(host, http_retry)
Expand Down
4 changes: 2 additions & 2 deletions opentargets/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
__author_email__ = 'support@targetvalidation.org'
__license__ = 'Apache License, Version 2.0'
__homepage__ = 'https://github.com/opentargets/opentargets-py'
__version__ = '3.0.0'
__version__ = '3.1.0'
__api_major_version__ = '3'
__description__ = 'Client for Open Targets REST API at targetvalidation.org'
__description__ = 'Client for Open Targets REST API at api.opentargets.io'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests>=2.11.1,<3.0
requests[socks]>=2.11.1,<3.0
cachecontrol==0.11.6
hyper==0.7.0
h2==2.6.2
Expand Down
3 changes: 2 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def testGetAssociationsForDisease(self):
for result in response:
self.assertEqual(result['disease']['efo_info']['label'], disease_label)

@unittest.expectedFailure
def testGetEvidence(self):
evidence_id = "03fba0599655b9040012b29cf0de8060"
response = self.client.get_evidence(evidence_id)
Expand Down Expand Up @@ -179,7 +180,7 @@ def testGetSimilarDisease(self):
self.assertGreater(len(response), 0)
result = next(response)
self.assertEqual(result['subject']['label'], disease_label)
self.assertEqual(result['object']['label'], 'inflammatory bowel disease')
self.assertEqual(result['object']['label'], "Crohn's disease")

def testGetEvidenceForDisease(self):
disease_label = 'medulloblastoma'
Expand Down

0 comments on commit baf7267

Please sign in to comment.