MCPcopy Index your code
hub / github.com/ahivert/tgtg-python

github.com/ahivert/tgtg-python @0.19.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.19.0 ↗ · + Follow
81 symbols 364 edges 13 files 22 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Actions Status codecov PyPI version

tgtg-python

Python client that help you to talk with TooGoodToGo API.

Python version: 3.9+

Handle:

  • create an account (/api/auth/vX/signUpByEmail)
  • login (/api/auth/vX/authByEmail)
  • refresh token (token/v1/refresh)
  • list stores (/api/item/vX)
  • get a store (/api/item/vX/:id)
  • get favorites (/api/discover/vX/bucket)
  • set favorite (/api/user/favorite/vX/:id/update)
  • create an order (/api/order/vX/create/:id)
  • abort an order (/api/order/vX/:id/abort)
  • get the status of an order (/api/order/vX/:id/status)
  • get active orders (/api/order/vX/active)
  • get inactive orders (/api/order/vX/inactive)
  • get delivery items (api/manufactureritem/v2)

Install

pip install tgtg

Use it

Retrieve tokens

Build the client with your email

from tgtg import TgtgClient

client = TgtgClient(email="<your_email>")
credentials = client.get_credentials()

You should receive an email from tgtg. The client will wait until you validate the login by clicking the link inside the email.

Once you clicked the link, you will get credentials and be able to use them

print(credentials)
{
    'access_token': '<your_access_token>',
    'refresh_token': '<your_refresh_token>',
    'cookie': '<cookie>',
}

Build the client from tokens

from tgtg import TgtgClient

client = TgtgClient(access_token="<access_token>", refresh_token="<refresh_token>", cookie="<cookie>")

Get items

# You can then get some items, by default it will *only* get your favorites
items = client.get_items()
print(items)

# To get items (not only your favorites) you need to provide location informations
items = client.get_items(
    favorites_only=False,
    latitude=48.126,
    longitude=-1.723,
    radius=10,
)
print(items)

Example response

[
    {
        "item": {
            "item_id": "64346",
            "item_price": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "sales_taxes": [],
            "tax_amount": {"code": "EUR", "minor_units": 0, "decimals": 2},
            "price_excluding_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "price_including_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "value_excluding_taxes": {
                "code": "EUR",
                "minor_units": 1500,
                "decimals": 2,
            },
            "value_including_taxes": {
                "code": "EUR",
                "minor_units": 1500,
                "decimals": 2,
            },
            "taxation_policy": "PRICE_INCLUDES_TAXES",
            "show_sales_taxes": False,
            "value": {"code": "EUR", "minor_units": 1500, "decimals": 2},
            "cover_picture": {
                "picture_id": "110628",
                "current_url": "https://images.tgtg.ninja/item/cover/2b69cbdd-43d3-4ade-bd51-50e338260859.jpg",
            },
            "logo_picture": {
                "picture_id": "110618",
                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
            },
            "name": "",
            "description": "Salva comida en Ecofamily Bufé y tu pack podrá contener: comidas caseras.",
            "can_user_supply_packaging": False,
            "packaging_option": "MUST_BRING_BAG",
            "collection_info": "",
            "diet_categories": [],
            "item_category": "MEAL",
            "badges": [
                {
                    "badge_type": "SERVICE_RATING_SCORE",
                    "rating_group": "LIKED",
                    "percentage": 93,
                    "user_count": 178,
                    "month_count": 5,
                }
            ],
            "favorite_count": 0,
            "buffet": False,
        },
        "store": {
            "store_id": "59949s",
            "store_name": "Ecofamily Bufé - Centro",
            "branch": "",
            "description": "",
            "tax_identifier": "",
            "website": "",
            "store_location": {
                "address": {
                    "country": {"iso_code": "ES", "name": "Spain"},
                    "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",
                    "city": "",
                    "postal_code": "",
                },
                "location": {"longitude": -4.776045, "latitude": 37.894249},
            },
            "logo_picture": {
                "picture_id": "110618",
                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
            },
            "store_time_zone": "Europe/Madrid",
            "hidden": False,
            "favorite_count": 0,
            "we_care": False,
        },
        "display_name": "Ecofamily Bufé - Centro",
        "pickup_location": {
            "address": {
                "country": {"iso_code": "ES", "name": "Spain"},
                "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",
                "city": "",
                "postal_code": "",
            },
            "location": {"longitude": -4.776045, "latitude": 37.894249},
        },
        "items_available": 0,
        "distance": 4241.995584076078,
        "favorite": True,
        "in_sales_window": False,
        "new_item": False,
    },
]

Get an item

(Using item_id from get_items response)

item = client.get_item(item_id=614318)
print(item)

Example response

```python { "item": { "item_id": "614318", "sales_taxes": [{"tax_description": "TVA", "tax_percentage": 5.5}], "tax_amount": {"code": "EUR", "minor_units": 13, "decimals": 2}, "price_excluding_taxes": {"code": "EUR", "minor_units": 236, "decimals": 2}, "price_including_taxes": {"code": "EUR", "minor_units": 249, "decimals": 2}, "value_excluding_taxes": {"code": "EUR", "minor_units": 0, "decimals": 2}, "value_including_taxes": {"code": "EUR", "minor_units": 0, "decimals": 2}, "taxation_policy": "PRICE_INCLUDES_TAXES", "show_sales_taxes": False, "cover_picture": { "picture_id": "620171", "current_url": "https://images.tgtg.ninja/item/cover/ac80c1b3-1386-46a8-ba80-c97b3a6e7e18.png", "is_automatically_created": False, }, "logo_picture": { "picture_id": "622046", "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png", "is_automatically_created": False, }, "name": "Panier petit déjeuner", "description": "Sauvez un panier-surprise réalisé à partir des délicieux articles d'un buffet petit déjeuner.", "food_handling_instructions": "", "can_user_supply_packaging": False, "packaging_option": "BAG_ALLOWED", "collection_info": "", "diet_categories": [], "item_category": "BAKED_GOODS", "buffet": True, "badges": [ { "badge_type": "SERVICE_RATING_SCORE", "rating_group": "LOVED", "percentage": 96, "user_count": 131, "month_count": 6, }, { "badge_type": "OVERALL_RATING_TRUST_SCORE", "rating_group": "LOVED", "percentage": 90, "user_count": 131, "month_count": 6, }, ], "positive_rating_reasons": [ "POSITIVE_FEEDBACK_FRIENDLY_STAFF", "POSITIVE_FEEDBACK_GREAT_QUANTITY", "POSITIVE_FEEDBACK_QUICK_COLLECTION", "POSITIVE_FEEDBACK_DELICIOUS_FOOD", "POSITIVE_FEEDBACK_GREAT_VALUE", "POSITIVE_FEEDBACK_GREAT_VARIETY", ], "average_overall_rating": { "average_overall_rating": 4.520325203252033, "rating_count": 123, "month_count": 6, }, "allergens_info": {"shown_on_checkout": False}, "favorite_count": 0, }, "store": { "store_id": "624740", "store_name": "Hôtel Les Matins de Paris & Spa", "branch": "", "description": "Vous y êtes. Où ? À South Pigalle (Sopi pour les adeptes), au coeur d’une décontraction trendy.\nVous en êtes : de ceux qui ont déniché un lieu joliment habité, là où se fredonne depuis tant de décennies des airs vivement enjoués. Parce que, pour la petite histoire, notre adresse fut dans les années 50' 60' le repaire des plus arty.\nPile ici, le premier restaurant américain parisien créé par le fantaisiste Leroy Haynes attirait un heureux tohu-bohu, une kyrielle de musiciens, de Ray Charles à Marianne Faithfull…\nAujourd'hui, à vous d'improviser ici un rendez-vous amical, à vous de composer là avec la paresse la plus joyeuse. Se mettre au voluptueux diapason du spa, suivre le rythme des conseils spontanés d’une équipe concernée sont aussi des moments pour vous écouter.\nEntendez-vous la petite musique du lieu ? L'âme des Matins de Paris donne assurément le bon tempo pour prendre ses quartiers, les plus inspirés. ", "tax_identifier": "FR43552132029", "website": "https://www.lesmatinsdeparis.com/", "store_location": { "address": { "country": {"iso_code": "FR", "name": "France"}, "address_line": "3 Rue Clauzel, 75009 Paris, France", "city": "", "postal_code": "", }, "location": {"longitude": 2.3393925, "latitude": 48.8788434}, }, "logo_picture": { "picture_id": "622046", "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png", "is_automatically_created": False, }, "store_time_zone": "Europe/Paris", "hidden": False, "favorite_count": 0, "items": [ { "item": { "item_id": "614318", "sales_taxes": [{"tax_description": "TVA", "tax_percentage": 5.5}], "tax_amount": {"code": "EUR", "minor_units": 13, "decimals": 2}, "price_excluding_taxes": { "code": "EUR", "minor_units": 236, "decimals": 2, }, "price_including_taxes": { "code": "EUR", "minor_units": 249, "decimals": 2, }, "value_excluding_taxes": { "code": "EUR", "minor_units": 0, "decimals": 2, }, "value_including_taxes": { "code": "EUR", "minor_units": 0, "decimals": 2, }, "taxation_policy": "PRICE_INCLUDES_TAXES", "show_sales_taxes": False, "cover_picture": { "picture_id": "620171", "current_url": "https://images.tgtg.ninja/item/cover/ac80c1b3-1386-46a8-ba80-c97b3a6e7e18.png", "is_automatically_created": False, }, "logo_picture": { "picture_id": "622046", "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png", "is_automatically_created": False, }, "name": "Panier petit déjeuner", "description": "Sauvez un panier-surprise réalisé à partir des délicieux articles d'un buffet petit déjeuner.", "food_handling_instructions": "", "can_user_supply_packaging": False, "packaging_option": "BAG_ALLOWED", "collection_info": "", "diet_categories": [], "item_category": "BAKED_GOODS", "buffet": True, "badges": [ { "badge_type": "SERVICE_RATING_SCORE", "rating_group": "LOVED", "percentage": 96, "user_count": 131, "month_count": 6, }, { "badge_type": "OVERALL_RATING_TRUST_SCORE", "rating_group": "LOVED", "percentage": 90, "user_count": 131, "month_count": 6, }, ], "positive_rating_reasons": [ "POSITIVE_FEEDBACK_FRIENDLY_STAFF", "POSITIVE_FEEDBACK_GREAT_QUANTITY", "POSITIVE_FEEDBACK_QUICK_COLLECTION", "POSITIVE_FEEDBACK_DELICIOUS_FOOD", "POSITIVE_FEEDBACK_GREAT_VALUE", "POSITIVE_FEEDBACK_GREAT_VARIETY", ], "average_overall_rating": { "average_overall_rating": 4.520325203252033, "rating_count": 123, "month_count": 6, },

Core symbols most depended-on inside this repo

login
called by 21
tgtg/__init__.py
_get_url
called by 15
tgtg/__init__.py
_post
called by 15
tgtg/__init__.py
get_favorites
called by 5
tgtg/__init__.py
get_items
called by 4
tgtg/__init__.py
get_item
called by 4
tgtg/__init__.py
set_favorite
called by 4
tgtg/__init__.py
create_order
called by 4
tgtg/__init__.py

Shape

Function 50
Method 26
Class 5

Languages

Python100%

Modules by API surface

tgtg/__init__.py26 symbols
tests/test_items.py17 symbols
tests/test_order.py10 symbols
tests/test_login.py8 symbols
tests/test_active.py6 symbols
tests/conftest.py4 symbols
tgtg/exceptions.py3 symbols
tests/test_api.py3 symbols
tests/test_signup.py2 symbols
tgtg/google_play_scraper.py1 symbols
tests/test_apk.py1 symbols

For agents

$ claude mcp add tgtg-python \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact