Skip to main content

PyPI - Downloads PyPI - Downloads

Unofficial Basic-Fit API Client

Disclaimer: This is an unofficial Python client for the Basic-Fit app API. It is not affiliated with, endorsed by, or in any way connected to Basic-Fit N.V. Use it with your own account, at your own risk.

Introduction

The Unofficial Basic-Fit API Client is an asynchronous Python library for the backend that powers the Basic-Fit mobile app. It lets you read your membership details, gym visit history, in-club body-composition measurements and achievement badges, and it exposes the public workout, recipe and club-finder content library. The client handles the OAuth2 token lifecycle — including Basic-Fit's rotating refresh tokens — so you can focus on the data.

Features

  • Authentication Management: Keeps a valid access token, refreshes automatically when it expires, and correctly persists the rotating refresh token Basic-Fit hands back on every refresh.
  • One-time browser login (PKCE): A helper that builds the authorize URL and exchanges the returned code for tokens. The sign-in itself happens in a real browser because the login page is protected by a bot-challenge WAF.
  • Membership info: Name, membership type, home club, card/membership number, add-ons and outstanding-debt flag.
  • Visit history: Full activity feed with a convenience filter for physical gym check-ins.
  • Body measurements: Weight, fat %, muscle, water and more from the in-club scales.
  • Badges: Earned achievement badges.
  • Content library: Search the workout catalog, the recipe catalog (with macros) and the club finder — all via the app's public Contentful endpoint.
  • Club busyness and opening hours: Each club's typical weekly busyness profile and whether it is open at a given time. Needs no account.
  • Typed models: Every response is parsed into a documented dataclass, with the raw payload kept on .raw for anything not yet modelled.

Features to be Added

  • Workout progress / logging endpoints

(feel free to PR if you manage to implement any of these features)

Installation

Ensure you have Python 3.11 or higher installed. You can install the package using pip:

pip install basicfit

Or, from a checkout:

pip install -r requirements.txt

Authentication

Basic-Fit uses OAuth2 Authorization Code + PKCE. The login page (login.basic-fit.com) sits behind an Imperva browser challenge, so it can't be automated headlessly — you sign in once in a normal browser. The token endpoint (auth.basic-fit.com) is not challenged, so all refreshes after that first login happen automatically in the background.

Refresh tokens rotate. Every refresh returns a new refresh token and invalidates the old one. Always persist the token set after each call — use the token_updated callback below and you never have to think about it.

One-time browser login

import asyncio
import aiohttp
from basicfit import AuthManager, TokenSet, start_login, parse_redirect

async def login():
    challenge = start_login()
    print("Open this URL and sign in:\n", challenge.authorize_url)
    # Your browser will try to open a
    # com.basicfit.trainingapp:/oauthredirect?code=... URL — copy it from the
    # address bar and paste it here:
    redirect = input("Paste the redirect URL: ").strip()
    code = parse_redirect(redirect, expected_state=challenge.state)

    async with aiohttp.ClientSession() as session:
        tokens = await AuthManager.async_exchange_code(
            session, code, challenge.verifier
        )
    # Persist this — it's all you need next time.
    print(tokens.to_dict())

asyncio.run(login())

Reusing a stored token

import json
from basicfit import BasicFitClient, TokenSet

def save(tokens):  # called automatically after every rotation
    with open("tokens.json", "w") as fh:
        json.dump(tokens.to_dict(), fh)

with open("tokens.json") as fh:
    tokens = TokenSet.from_dict(json.load(fh))

client = BasicFitClient.create(tokens, token_updated=save)

Or, if you only have the raw refresh token string:

client = BasicFitClient.from_refresh_token("<refresh-token>", token_updated=save)

Usage

The client manages its own aiohttp session (pass your own via session= if you prefer) and works as an async context manager.

import asyncio
from basicfit import BasicFitClient, TokenSet

async def main():
    async with BasicFitClient.from_refresh_token("<refresh-token>") as client:
        # Membership
        member = await client.get_member()
        print(member.name, member.membership_type, member.home_club)

        # Gym visits (last 30 days by default; accepts date ranges, max 365 days)
        visits = await client.get_visits()
        print(f"{len(visits)} visits")
        for v in visits[:5]:
            print(v.date, v.club)

        # Body composition (most recent first)
        for m in await client.get_body_measurements(limit=3):
            print(m.date, m.weight, "kg", m.fat, "% fat")

        # Achievement badges
        for b in await client.get_badges():
            print(b.name, b.earned_at)

asyncio.run(main())

Content library

The workout, recipe and club look-ups hit Basic-Fit's public content endpoint and don't require authentication (they work even before login):

async with BasicFitClient.from_refresh_token("<refresh-token>") as client:
    workouts = await client.search_workouts("full body", limit=5)
    for w in workouts:
        print(w.name, w.duration_min, "min", w.body_parts)

    recipes = await client.search_recipes("protein", limit=5)
    for r in recipes:
        print(r.name, r.kcal, "kcal", r.protein_g, "g protein")

    clubs = await client.search_clubs(city="Amsterdam")
    for c in clubs:
        print(c.display_name, c.address, "closed" if c.closed else "open")
        print(client.club_image_url(c.kp_number))

Without an account

BasicFitContentClient reaches the same content library without any login or token. BasicFitClient uses one internally, and exposes it as client.content.

from basicfit import BasicFitContentClient

async with BasicFitContentClient() as content:
    clubs = await content.search_clubs(city="Amsterdam")

Club busyness

Most clubs publish a weekly busyness profile: one number for every hour of every weekday. It is a typical week, not live occupancy. Basic-Fit does not document the unit, so compare values within one club or use the percentage of the club's weekly peak. A value of 0 usually means the club is closed or has no data for that hour. A club without a profile gives None. This works without an account.

from datetime import datetime
from zoneinfo import ZoneInfo
from basicfit import BasicFitContentClient

async with BasicFitContentClient() as content:
    club = await content.resolve_club("1006")  # club id, KP number or exact name
    busyness = club.busyness_profile if club else None
    if busyness:
        now = datetime.now(ZoneInfo("Europe/Amsterdam"))  # the club's local time
        print(busyness.value_at(now), "of a weekly peak of", busyness.weekly_peak)
        print(busyness.relative_at(now), "% of the weekly peak")
        print("busiest later today:", busyness.busiest_hour(now))
        print("quietest later today:", busyness.quietest_hour(now))
        print("open now:", club.is_open_at(now))

get_club_busyness(club_id=..., kp_number=...) returns the profile directly. Member.home_club_id holds the homeClubId the member API returns; which club identifier that is has not been verified, so pass it to resolve_club, which tries it as a club id, a KP number and a name.

Quickstart script

examples/quickstart.py runs the whole flow end to end: it does the one-time browser login, stores the token in tokens.json, and prints your membership, recent visits, latest weight and badge count. On later runs it reuses (and silently rotates) the stored token.

python examples/quickstart.py

Home Assistant

A companion Home Assistant integration built on this package lives at HA-Basic-Fit — install it via HACS to get your visits, membership, weight and badges as sensors.

Notes

  • Locales: the content library uses Contentful locale codes (en-US, nl, fr, es, de) — note nl, not nl-NL. The client normalises unknown values to en-US.
  • Ranges: the activities endpoint accepts spans up to 365 days; longer ranges are clamped.
  • Errors: the package raises BasicFitAuthError (sign in again), BasicFitAPIError (bad response, carries status_code), BasicFitNetworkError (timeout/connection) and BasicFitValidationError (bad arguments) — all subclasses of BasicFitError.

Supporting the project

This project is free and stays free. If it is useful to you, you can support its development through GitHub Sponsors. Sponsorship is voluntary and unlocks nothing: every feature, fix and security update ships in the public release.

License

MIT — see LICENSE.

Metadata

Release files for basicfit 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for basicfit 1.1.0
File Size Uploaded Provenance Actions
basicfit-1.1.0.tar.gz 39.6 kB With provenance Details for basicfit-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for basicfit 1.1.0
File Interpreter ABI Platform Actions
basicfit-1.1.0-py3-none-any.whl Python 3 none any Details for basicfit-1.1.0-py3-none-any.whl

Total release size: 65.0 kB

Release files / basicfit-1.1.0.tar.gz

Download URL basicfit-1.1.0.tar.gz
Size 39.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0b6557cc2b077ff1b0ae52628bab4915e083bd79d8562d2e7609dd3c46bc0900
BLAKE2b-256 checksum
How to use checksums
d72c035298f281904aaadee81b588a355ff2d581f8773deeb3b65f9f9368258d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / basicfit-1.1.0-py3-none-any.whl

Download URL basicfit-1.1.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3eb2656a564d136fba070652d4f17da6e0c7b7d9bf49d2e6c4404fbaafad070f
BLAKE2b-256 checksum
How to use checksums
ac0f95f4b1ce2602a950fdb17a22bc5b8d39c6ea93d0529add3c65dd39be28cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for basicfit 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for basicfit-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page