The pyconclas is a client written in Python to use the service Conclas.
Project description
Our Python client helps you to gain knowledge on your contents from any system that has Internet connection. As the request reach our servers, we immediately start classifying its contents for you.
Getting Started
You can get our Python client via pip:
pip install pyconclas
Each project has a token, a series of characters used to authenticate the requester identity as well as identify to which project the request will be attached. This is passed to the API instance as follows:
from pyconclas.api import Conclas
api = Conclas(token='<token>')
After that, you are ready to classify your contents.
Direct classify
direct_classify requests the categories of the given contents, blocking further execution until it receives the result from ConClas. Please read the direct mode reference for more details.
Request
Here’s what a request for direct_classify looks like:
contents = [
{
'url': 'www.qwerty123456789.com'
},
{
'doc': {
'short_text': 'This is an example',
'long_text': 'This is a DOC long text for ConClas, working as an example request'
}
}
]
api.direct_classify(contents)
contents (list): JSON-like object containing a list of contents to be classified. See the contents reference for more details.
Result
>>> api.result
{
'took': 3,
'result': [
{
'sent': {
'url': 'www.qwerty123456789.com'
},
'categories': [1, 2, 3, 4, 5],
'errors': []
}, {
'sent': {
'doc': {
'short_text': 'This is an example',
'long_text': 'This is a DOC long text for ConClas, working as an example request'
'brands': ''
}
},
'categories': [10, 11, 12, 13, 14, 15],
'errors': []
}
]
}
took (int): Time elapsed during classification.
result (list): A list containing dicts with each received content, their categories, and eventual errors that happened. See the results reference for more details.
Indirect classify
indirect_classify requests the categories of the given contents, without blocking further execution. The results are sent to a callback URL when finished. Please read the indirect mode reference for more details.
Request
Here’s what a request for indirect_classify looks like:
contents = [
{
'url': 'www.qwerty123456789.com'
},
{
'doc': {
'short_text': 'This is an example',
'long_text': 'This is a DOC long text for ConClas, working as an example request'
}
}
]
callback = 'http://www.callback.com'
api.indirect_classify(contents, callback)
contents (list): JSON-like object containing a list of contents to be classified. See the contents reference for more details.
Result
Here’s what a result for indirect_classify mode looks like:
>>> api.result
{'acknowledged': 'True'}
acknowledged (string): Confirms the contents where received and will be classified. Its value is always 'True'.
Exceptions
Exception |
Description |
---|---|
ContentsKeyException |
|
URLInvalidException |
|
JsonKeysException |
|
ConclasHTTPError |
|
ParameterTypeError |
|
EmptyParameterException |
|
DocMinException |
|
ConclasRequestException |
|
InvalidTokenException |
|
InvalidBodyException |
|
InvalidModeException |
API limits
In order to prevent abuse in use, please follow these limits:
Maximum message size: 1,000 contents
Maximum URL length: 2,083 characters
Minimum DOC text length (short text + long text): 25 characters
Maximum DOC short text length: 1,000 characters
Maximum DOC long text length: 20,000 characters
Maximum DOC brands length: 5,000 characters
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.