Package: python-bring-api
Bring Shopping Lists APIAn unofficial python package to access the Bring! shopping lists API.This is aminimalpython port of thenode-bring-apibyfoxriver76. All credit goes to him for making this awesome API possible!DisclaimerThe developers of this module are in no way endorsed by or affiliated with Bring! Labs AG, or any associated subsidiaries, logos or trademarks.Installationpip install python-bring-apiDocumentationSee below for usage examples. SeeExceptionsfor API-specific exceptions and mitigation strategies for common exceptions.Usage ExampleThe API is available both sync and async, where sync is the default for simplicity. Both implementations of each function use the same async HTTP libraryaiohttpin the back.Syncimportloggingimportsysfrompython_bring_api.bringimportBringlogging.basicConfig(stream=sys.stdout,level=logging.DEBUG)# Create Bring instance with email and passwordbring=Bring("MAIL","PASSWORD")# Loginbring.login()# Get information about all available shopping listslists=bring.loadLists()["lists"]# Save an item with specifications to a certain shopping listbring.saveItem(lists[0]['listUuid'],'Milk','low fat')# Save another itembring.saveItem(lists[0]['listUuid'],'Carrots')# Get all the items of a listitems=bring.getItems(lists[0]['listUuid'])print(items)# Check off an itembring.completeItem(lists[0]['listUuid'],'Carrots')# Remove an item from a listbring.removeItem(lists[0]['listUuid'],'Milk')Asyncimportaiohttpimportasyncioimportloggingimportsysfrompython_bring_api.bringimportBringlogging.basicConfig(stream=sys.stdout,level=logging.DEBUG)asyncdefmain():asyncwithaiohttp.ClientSession()assession:# Create Bring instance with email and passwordbring=Bring("MAIL","PASSWORD",sessionAsync=session)# Loginawaitbring.loginAsync()# Get information about all available shopping listslists=(awaitbring.loadListsAsync())["lists"]# Save an item with specifications to a certain shopping listawaitbring.saveItemAsync(lists[0]['listUuid'],'Milk','low fat')# Save another itemawaitbring.saveItemAsync(lists[0]['listUuid'],'Carrots')# Get all the items of a listitems=awaitbring.getItemsAsync(lists[0]['listUuid'])print(items)# Check off an itemawaitbring.completeItemAsync(lists[0]['listUuid'],'Carrots')# Remove an item from a listawaitbring.removeItemAsync(lists[0]['listUuid'],'Milk')asyncio.run(main())ExceptionsIn case something goes wrong during a request, several exceptions can be thrown.
They will either be BringRequestException, BringParseException, or BringAuthException, depending on the context. All inherit from BringException.Another asyncio event loop is already runningBecause even the sync methods use async calls under the hood, you might encounter an error that another asyncio event loop is already running on the same thread. This is expected behavior according to the asyncio.run()documentation. You cannot call the sync methods when another event loop is already running. When you are already inside an async function, you should use the async methods instead.Exception ignored: RuntimeError: Event loop is closedDue to a known issue in some versions of aiohttp when using Windows, you might encounter a similar error to this:Exceptionignoredin:<function_ProactorBasePipeTransport.__del__at0x00000000>Traceback(mostrecentcalllast):File"C:\...\py38\lib\asyncio\proactor_events.py",line116,in__del__self.close()File"C:\...\py38\lib\asyncio\proactor_events.py",line108,incloseself._loop.call_soon(self._call_connection_lost,None)File"C:\...\py38\lib\asyncio\base_events.py",line719,incall_soonself._check_closed()File"C:\...\py38\lib\asyncio\base_events.py",line508,in_check_closedraiseRuntimeError('Event loop is closed')RuntimeError:EventloopisclosedYou can fix this according tothisstackoverflow answer by adding the following line of code before executing the library:asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())Changelog3.0.0Change backend library from requests to aiohttp, thanks to@miaucl!
This makes available async versions of all methods.Fix encoding of request data, thanks to@miaucl!2.1.0Add notify() method to send push notifications to other list members, thanks to@tr4nt0r!Add method to complete items, thanks to@tr4nt0r!Fix error handling in login method, thanks to@tr4nt0r!2.0.0Add exceptions and typings, thanks to@miaucl!Important: Unsuccessful HTTP status codes will now raise an exception.Module now requires Python version >= 3.8.1.2.2Clean up unused code 🧹1.2.1Fix encoding in login request, thanks to@tony059!1.2.0Add function to update an item, thanks to@Dielee!1.1.2Add option to provide own headers, thanks to@Dielee!1.1.0Add item details endpoint, thanks to@Dielee!1.0.2Fixed error handling
Added response return to login1.0.1Add github repo1.0.0Initial release