diff --git a/README.md b/README.md index ba44a06b8..2caa77750 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ Then run `source ~/.bash_profile` on the command line to ensure the environment ## Example API client usage ``` -import matroid from matroid.client import Matroid api = Matroid(client_id = 'abc', client_secret = '123') diff --git a/VERSION b/VERSION index 6d7de6e6a..9084fa2f7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 +1.1.0 diff --git a/matroid/__init__.py b/matroid/__init__.py index bb409a2f3..96492f880 100644 --- a/matroid/__init__.py +++ b/matroid/__init__.py @@ -1 +1,2 @@ from __future__ import absolute_import, division, print_function, unicode_literals +import matroid.client diff --git a/matroid/client.py b/matroid/client.py index c6d69e4a1..a89d6c39c 100644 --- a/matroid/client.py +++ b/matroid/client.py @@ -3,24 +3,68 @@ import sys from matroid import error -from src.helpers import api_call +from matroid.src.helpers import api_call -BASE_URL = 'https://www.matroid.com/api/v1' -DEFAULT_GRANT_TYPE = 'client_credentials' +BASE_URL = "https://www.matroid.com/api/v1" +DEFAULT_GRANT_TYPE = "client_credentials" class MatroidAPI(object): - from src.helpers import bytes_to_mb, check_errors, format_response, save_token, Token, FileReader - from src.accounts import account_info, retrieve_token - from src.detectors import create_detector, delete_detector, finalize_detector, get_detector_info, import_detector, redo_detector, search_detectors - from src.images import classify_image, localize_image - from src.videos import classify_video, get_video_results - from src.streams import create_stream, delete_monitoring, delete_stream, get_monitoring_result, kill_monitoring, monitor_stream, search_monitorings, search_streams - from src.labels import create_label_with_images, delete_label, get_annotations, get_label_images, update_annotations, update_label_with_images - from src.collections import create_collection_index, create_collection, delete_collection_index, delete_collection, get_collection_task, get_collection, kill_collection_index, query_collection_by_scores, query_collection_by_image, update_collection_index + from matroid.src.helpers import ( + bytes_to_mb, + check_errors, + format_response, + save_token, + Token, + FileReader, + ) + from matroid.src.accounts import account_info, retrieve_token + from matroid.src.detectors import ( + create_detector, + delete_detector, + finalize_detector, + get_detector_info, + import_detector, + redo_detector, + search_detectors, + ) + from matroid.src.images import classify_image, localize_image + from matroid.src.videos import classify_video, get_video_results + from matroid.src.streams import ( + create_stream, + delete_monitoring, + delete_stream, + get_monitoring_result, + kill_monitoring, + monitor_stream, + search_monitorings, + search_streams, + ) + from matroid.src.labels import ( + create_label_with_images, + delete_label, + get_annotations, + get_label_images, + update_annotations, + update_label_with_images, + ) + from matroid.src.collections import ( + create_collection_index, + create_collection, + delete_collection_index, + delete_collection, + get_collection_task, + get_collection, + kill_collection_index, + query_collection_by_scores, + query_collection_by_image, + update_collection_index, + ) - def __init__(self, base_url=BASE_URL, client_id=None, client_secret=None, options={}): - """ + def __init__( + self, base_url=BASE_URL, client_id=None, client_secret=None, options={} + ): + """ base_url: the API endpoint client_id: OAuth public API key client_secret: OAuth private API key @@ -30,36 +74,37 @@ def __init__(self, base_url=BASE_URL, client_id=None, client_secret=None, option set access_token with your auth token e.g., 43174a480adebf5b8e2bf39c0dcb53f1, to preload the token instead of requesting it from the server """ - from src.helpers import get_endpoints + from src.helpers import get_endpoints - if not client_id: - client_id = os.environ.get('MATROID_CLIENT_ID', None) + if not client_id: + client_id = os.environ.get("MATROID_CLIENT_ID", None) - if not client_secret: - client_secret = os.environ.get('MATROID_CLIENT_SECRET', None) + if not client_secret: + client_secret = os.environ.get("MATROID_CLIENT_SECRET", None) - if not client_id or not client_secret: - raise error.AuthorizationError( - message='Both client_id and client_secret parameters are required') + if not client_id or not client_secret: + raise error.AuthorizationError( + message="Both client_id and client_secret parameters are required" + ) - self.client_id = client_id - self.client_secret = client_secret - self.base_url = base_url - self.token = None - self.grant_type = DEFAULT_GRANT_TYPE - self.json_format = options.get('json_format', True) - self.print_output = options.get('print_output', False) - self.filereader = self.FileReader() + self.client_id = client_id + self.client_secret = client_secret + self.base_url = base_url + self.token = None + self.grant_type = DEFAULT_GRANT_TYPE + self.json_format = options.get("json_format", True) + self.print_output = options.get("print_output", False) + self.filereader = self.FileReader() - token = options.get('access_token') + token = options.get("access_token") - if token: - token_type = 'Bearer' - # if the token's lifetime is shorter than this, the client will request a refresh automatically - lifetime_in_seconds = 7 * 24 * 60 * 60 - self.token = self.Token(token_type, token, lifetime_in_seconds) + if token: + token_type = "Bearer" + # if the token's lifetime is shorter than this, the client will request a refresh automatically + lifetime_in_seconds = 7 * 24 * 60 * 60 + self.token = self.Token(token_type, token, lifetime_in_seconds) - self.endpoints = get_endpoints(self.base_url) + self.endpoints = get_endpoints(self.base_url) Matroid = MatroidAPI diff --git a/matroid/version.py b/matroid/version.py index 6732d5aae..2a3eb2f3e 100644 --- a/matroid/version.py +++ b/matroid/version.py @@ -1 +1 @@ -VERSION = '1.0.2' +VERSION = "1.1.0" diff --git a/setup.py b/setup.py index fe6c8abc4..a5b8f5028 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,19 @@ -from version import VERSION import os import sys -try: - from setuptools import setup -except ImportError: - from distutils.core import setup +from setuptools import setup, find_packages -sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'matroid')) +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "matroid")) +from version import VERSION setup( - name='matroid', + name="matroid", version=VERSION, - description='Matroid API Python Library', - author='Matroid', - author_email='support@matroid.com', - url='https://github.com/matroid/matroid-python', - install_requires=['requests'], - packages=['matroid'], - use_2to3=True + description="Matroid API Python Library", + author="Matroid", + author_email="support@matroid.com", + url="https://github.com/matroid/matroid-python", + install_requires=["requests"], + packages=find_packages(), + use_2to3=True, )