Deepomatic API Client for Python.
This client have been made in order to help you integrating our services within your apps in python.
A demo code can be run in demo.py. It will explain you how to :
- Play with dbs.
- Make batched queries.
- Searching based on similarity into your dbs.
- Find a perfect match.
- Use our fashion detection API.
sudo pip install -r requirements.txt
Initialize a client. Does not make any call to the server.
# You should find your appID and apiKey in your account on developpers.deepomatic.com
client = deepomatic.Client(appID, apiKey)Since most of server calls need some processing time, you will often receive a Task (json dictionary). Task are very simple to use.
Fields:
- id
- data
- status
- error
- date_created
- date_updated
When the task "status" is equal to "succes" you can find the request result in the "data" field.
pt = deepomatic.Point(0,0)You can create a polygon with the Polygon class :
poly = deepomatic.Polygon()To add points to the polygon, just use the addPoint method :
poly.addPoint(deepomatic.Point(1,2))If you want to add multiple points at once, just use the addPoints methode:
poly.addPoints([deepomatic.Point(1,2), deepomatic.Point(2,2), deepomatic.Point(1,1)])For a polygon to be valid, it must have at least 3 points.
The bbox class takes 2 points, min and max.
bbox = deepomatic.Bbox(deepomatic.Point(1,2), deepomatic.Point(2,3))The class ImgsSend, allows you to create an image with multiple fields :
imgs = deepomatic.ImgsSend(sourceType, source, polygon = None, bbox = None)You can add images by using the addImg method with the same parameters:
imgs.addImg(sourceType, source, polygon = None, bbox = None)You can use url, base64 or file for the sourceType.
You can send multiple request type on a batch : PUT, POST, GET, DELETE.
batch = deepomatic.BatchObject(dbname)
batch.deleteObject(id)
batch.getObject(id)
batch.addObject(imgs, id = None)To send the batch to the API, just use the client batchRequest() methode :
client.batchRequest(batch, true)The database is created when the first object is indexed
response = client.getDBs()imgs = deepomatic.ImgsSend("url", "my_url", polygon = None, bbox = None)
data = { "myData": "beautiful shoes" }
id = "myID"
# if id is not specified the server will generate an id returned it in the response
# if the id already exists on the server side, it will be overwritten
response = client.saveObject("db_name", imgs, data = data, id = id)imgs = deepomatic.ImgsSend("file", "my_file.jpg", polygon = None, bbox = None)
data = { "myData": "beautiful shoes" }
id = "myID"
# if id is not specified the server will generate an id returned it in the response
# if the id already exists on the server side, it will be overwritten
response = client.saveObject("db_name", imgs, data = data, id = id)response = client.getObject("db_name", "myObjectID")# if wait = True it will wait until the task is completed
response = client.deleteObject("db_name", "myObjectID", wait = True)# if wait = True it will wait until the task is completed else, it will return the task id
response = client.clearDB("db_name", wait = True)# if wait = True it will wait until the task is completed
response = client.deleteDB("db_name", wait = True)# if wait = True it will wait until the task is completed else it will return the task id
img_url = {"url" : "url_img"}
response = client.search("db_name", img_url)
# you can also use file upload
img_file = {"file" : "path_to_file"}
response = client.search("db_name", img_file)You can use url, base64 or file as source.
img = "url_img"
response = client.getCount("db_name")requests = deepomatic.BatchObject(dbname)
url_base = "http://example.com/image_%d.jpg"
for i in range(10):
# refer to https://api.deepomatic.com for the content of the requests
imgs = deepomatic.ImgsSend(url, url_base % i)
requests.addObject(imgs, name)
# if wait = True it will wait until the task is completed
response = client.batchRequest(requests, wait = True)# if wait = True it will wait until the task is completed else it will send you back a task id
response = client.detect("fashion", "img_url", wait = True)task = client.retrieveTask(task_id)