Skip to main content

Unofficial package to access Bring! shopping lists API.

Project description

Bring! Shopping Lists API

PyPI version

An unofficial python package to access the Bring! shopping lists API.

Credits

This implementation of the api is derived from the generic python implementation by eliasball, which uses the legacy version of the api. This fork has been synced last time on 2024-02-11 and diverges from that point on using the non-legacy version. The implementation of eliasball is a minimal python port of the node-bring-api by foxriver76. All credit goes to him for making this awesome API possible!

Disclaimer

The developers of this module are in no way endorsed by or affiliated with Bring! Labs AG, or any associated subsidiaries, logos or trademarks.

Installation

pip install bring-api

Documentation

See below for usage examples. See Exceptions for API-specific exceptions and mitigation strategies for common exceptions.

Usage Example

The API is based on the async HTTP library aiohttp.

import aiohttp
import asyncio
import logging
import sys

from bring_api.bring import Bring

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

async def main():
  async with aiohttp.ClientSession() as session:
    # Create Bring instance with email and password
    bring = Bring(session, "MAIL", "PASSWORD")
    # Login
    await bring.login()

    # Get information about all available shopping lists
    lists = (await bring.load_lists())["lists"]

    # Save an item with specifications to a certain shopping list
    await bring.save_item(lists[0]['listUuid'], 'Milk', 'low fat')

    # Save another item
    await bring.save_item(lists[0]['listUuid'], 'Carrots')

    # Get all the items of a list
    items = await bring.get_list(lists[0]['listUuid'])
    print(items)

    # Check off an item
    await bring.complete_item(lists[0]['listUuid'], 'Carrots')

    # Remove an item from a list
    await bring.remove_item(lists[0]['listUuid'], 'Milk')

asyncio.run(main())

Exceptions

In 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

With the async calls, 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 use more than one aiohttp session per thread, reuse the existing one!

Exception ignored: RuntimeError: Event loop is closed

Due to a known issue in some versions of aiohttp when using Windows, you might encounter a similar error to this:

Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000000>
Traceback (most recent call last):
  File "C:\...\py38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\...\py38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\...\py38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\...\py38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

You can fix this according to this stackoverflow answer by adding the following line of code before executing the library:

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Dev

Setup the dev environment using VSCode, is is highly recommended.

python -m venv .venv
source .venv/bin/activate
pip install -r requirements_dev.txt

Install pre-commit

pre-commit install

# Run the commit hooks manually
pre-commit run --all-files

# Run tests locally (using a .env file is supported and recommended)
export EMAIL=...
export PASSWORD=...
export LIST=...
python test.py

Following VSCode integrations may be helpful:

CHANGELOG

0.3.1

  • Unpin requirements and remove subdependencies (tr4nt0r)

0.3.0

  • Refactor for PEP8 compliance and code clean-up (breaking change) (tr4nt0r)

0.2.0

  • Add new method does_user_exist (tr4nt0r)
  • Fixes for test workflow

0.1.4

Add test workflow.

0.1.3

Add mypy for type-checking.

0.1.2

Add ruff as formatter and linter.

0.1.1

Change name of package to bring-api.

0.1.0

Test publish workflow for pypi, no code related changes.

0.0.1

Initial commit based on 3.0.0 from eliasball.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bring-api-0.3.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bring_api-0.3.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file bring-api-0.3.1.tar.gz.

File metadata

  • Download URL: bring-api-0.3.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for bring-api-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0639336c17aba567d2cdc0a099c61b5724bc7f7878a7c0d93c788fd8bab9d5fd
MD5 d6974ffb8e8bb69c29747d177b77fefc
BLAKE2b-256 57de79d8ce6763d13182ab55fdf4cad255001462a605e088c755d1bc188f9376

See more details on using hashes here.

File details

Details for the file bring_api-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: bring_api-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for bring_api-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a321435235cb3b6aaad77a5dab7ec9b31f57fe8f9c26538b7bb052398fe32f75
MD5 aff1587970c409a219054d28314b6eba
BLAKE2b-256 1a745fd4de36cfc77d04c2dab949399200fa1593eb40fdcba455cb93c5982d3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page