Package: neuroio
Python API client for NeuroIORead Latest Documentation-Browse GitHub Code RepositoryThis library strives to be a complete mirror of official NeuroIO API in terms of methods and interfaces.Official latest API documentation can be foundhere.For your convenience, you can make API calls using sync or async (asyncio) interface.InstallationpipinstallneuroioNote that it is always recommended pinning version of your installed packages.Usage example (sync)An example of how to create a source:fromneuroioimportClientif__name__=='__main__':# api_token is just str with your API token from NeuroIOapi_token="abcd012345"# Now create instance of Client. There should be only one per process.client=Client(api_token=api_token)# Issue API request to create sourceclient.sources.create(name="test_name")Now that we have our source created, we can create person inside that source:fromneuroioimportClientdefcreate_persons_example(client:Client):source_name="test_name"withopen("image.png","rb")asf:response=client.persons.create(image=f,source=source_name,facesize=1000,create_on_ha=True,create_on_junk=True,identify_asm=True)print("Persons Create Response:\n",response.json(),flush=True)if__name__=='__main__':# api_token is just str with your API token from NeuroIOapi_token="abcd012345"# Now create instance of Client. There should be only one per process.client=Client(api_token=api_token)# Issue API request to create a personcreate_persons_example(client)Now that we have our source & person created, we can search for persons:fromneuroioimportClientdefsearch_persons_example(client:Client):withopen("image.png","rb")asf:response=client.persons.search(image=f,identify_asm=True)print("Persons Search Response:\n",response.json(),flush=True)if__name__=='__main__':# api_token is just str with your API token from NeuroIOapi_token="abcd012345"# Now create instance of Client. There should be only one per process.client=Client(api_token=api_token)# Issue API request to search personssearch_persons_example(client)An example of how to listen for events:importasyncioimportjsonimportloggingimportsignalfromneuroioimportEventListenerasyncdefevent_handler_func(event_message:str):# NOTE: this must be awaitable and accept single param Union[str, bytes]json_message=json.loads(event_message)is_ping_response="PING"injson_message.keys()is_auth_response="auth"injson_message.keys()is_error_response="error"injson_message.keys()ifis_ping_response:ifjson_message["PING"]!="PONG":# something is wrong with socket connectionraiseRuntimeError()else:# this is correct pong response on our periodic pingslogging.info("Connection is alive")elifis_auth_response:logging.info("Authorized successfully")elifis_error_response:# something is wrong with provided tokenlogging.info(json_message["error"],flush=True)else:# this must be event about entry itself# now you can inspect json_message for information about thatlogging.info(json_message["data"]["face_image"])asyncdefshutdown(signal,loop):"""Cleanup tasks tied to the service's shutdown."""logging.info(f"Received exit signal{signal.name}...")tasks=[tfortinasyncio.all_tasks()iftisnotasyncio.current_task()][task.cancel()fortaskintasks]logging.info(f"Cancelling{len(tasks)}outstanding tasks")awaitasyncio.gather(*tasks,return_exceptions=True)loop.stop()if__name__=="__main__":logging.getLogger().setLevel(logging.INFO)# NOTE: You are advised to hook-up uvloop here for improved performanceapi_token="1234567890"events_listener=EventListener(api_token=api_token,event_handler_func=event_handler_func)loop=asyncio.get_event_loop()# May want to catch other signals toosignals=(signal.SIGHUP,signal.SIGTERM,signal.SIGINT)forsinsignals:loop.add_signal_handler(s,lambda_s=s:asyncio.create_task(shutdown(_s,loop)))try:loop.create_task(events_listener.listen())loop.run_forever()finally:loop.close()logging.info("Successfully shutdown")For more examples and usage, please refer to thedocs.Development setupTo install all the development requirements:pipinstall--upgradepip
pipinstallpoetry
poetryinstall--no-rootTo run linters & test suite:./scripts/test.shRelease History0.1.0Support for WebSocket EventsDrop Python 3.6 support0.0.9Fixes to the sources API in terms of required fields0.0.8Updated library to latest API version (at the time of this release - 1.3.1)Updated README & docs0.0.7Updated library to latest API version (at the time of this release - 1.3.0)Updated requirementsUpdated README & docs0.0.6Updated library to latest API version (at the time of this release - 1.2.1)Updated README & docs0.0.5Fixed persistent connection problemsUpdated requirementsCodebase cleanup0.0.4Changed the way how we treat httpx connection - now we don't close it after every request (which was supposedly right way in httpx docs)0.0.3Updated httpx version, disabled cruft check since it just messes up project filesLicenseDistributed under the MIT license. SeeLICENSEfor more information.ContributingFork it (https://github.com/yourname/yourproject/fork)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Create a new Pull Request