Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.1.0
1 change: 1 addition & 0 deletions matroid/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import matroid.client
117 changes: 81 additions & 36 deletions matroid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion matroid/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.0.2'
VERSION = "1.1.0"
25 changes: 11 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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,
)