Skip to main content

virtuagym

CI PyPI

A typed Python client for the Virtuagym API — v1 (api key + club secret) and v3 (OAuth client credentials) — with sync and async clients.

  • Typed models — every response is validated onto frozen pydantic models: responses that don't match the schema fail loudly instead of corrupting your data.
  • Battle-tested against the live API — the behavior of every endpoint (pagination cursors, envelope quirks, type inconsistencies) was verified live; see API-FINDINGS for everything the docs don't tell you.
  • Pagination handled — iterate lazily page by page, or fetch everything with one call. Duplicate rows caused by the API's inclusive cursors are deduplicated for you.
  • Sync and asyncVirtuaGymClientV1/VirtuaGymClientV3 on httpx's sync client, AsyncVirtuaGymClientV1/AsyncVirtuaGymClientV3 on its async client, identical method surfaces.
  • Sibling packages: Node.js/TypeScript and PHP.

Installation

pip install virtuagym

Requires Python 3.10+.

API v1 (api key + club secret)

You need three values, all found in Virtuagym under Business settings → Business Info → Advanced: your API key, the "Club Key" (club secret), and your club id.

from virtuagym import VirtuaGymClientV1

client = VirtuaGymClientV1(
    api_key="...",
    club_secret="...",
    club_id=12345,
)

# Lazily, page by page — each HTTP request only happens when you ask for the next page
for page in client.members():
    print(f"received {len(page)} members")

# Or collect every page into a single list
members = client.all_members()

# Incremental sync (timestamp in ms)
changed = client.all_members(sync_from=last_sync_timestamp)

# Single member with membership instances embedded
member = client.member(7302399, with_="memberships")

# Mutations re-fetch and return the canonical record
created = client.create_member(
    {"firstname": "John", "lastname": "Doe", "email": "john@example.com"}
)
updated = client.update_member(created.member_id, {"gender": "f"})
upserted = client.create_or_update_member(
    {"external_id": "1ABC234567", "firstname": "John", "lastname": "Doe"}
)

The full v1 surface: employees, members, activate_user, events, membership_instances / membership_definitions / create_membership_instance, event_participants (bookings), club_taxes, income_categories, invoices, visits, member_notes, member_credits / add_member_credits, assign_workout, bodymetrics. Every list endpoint has a lazy iterator (members()) and a collector (all_members()). Mutation payloads are plain dicts with the API's wire-format keys.

Worth knowing (all verified live): single-resource GETs 404 with statuscode 420; the notes endpoint is capped at the newest 500 rows; notes and credits use seconds for sync_from while most endpoints use milliseconds; credits rows have no unique id and page-boundary duplicates are deduplicated for you.

API v3 (OAuth)

The v3 API is a separate stack behind gateway.services.virtuagym.com, authenticated with OAuth client credentials (register via api@virtuagym.com). Tokens are requested and renewed automatically (club-bound, ~30 min lifetime). Which v3 resources you can reach depends on the scopes Virtuagym registered for your client — without the right scope the API answers a misleading 401 Token not valid..

import time

from virtuagym import VirtuaGymClientV3

client = VirtuaGymClientV3(
    client_id="...",
    client_secret="...",
    club_id=12345,
)

# Leads — the live API serializes EVERY lead field as a string
leads = client.all_leads()
lead = client.lead(751563)
created = client.create_lead({"firstname": "Jane", "lastname": "Doe", "email": "jane@example.com"})
client.update_lead(created.lead_id, {"status_id": 12})  # Closed won

# Schedule (requires the schedule_public_api_club_<club_id> scope)
now = int(time.time() * 1000)
week = 7 * 24 * 3600 * 1000

events = client.all_events(date_start=now, date_end=now + week, event_type="appointment")
bookings = client.all_event_bookings(date_start=now, date_end=now + week, member_id=42)

result = client.create_booking(events[0].event_id, {"member_id": 42})
# Inspect result.bookings[0].reason — see BOOKING_REASON_CODES in
# virtuagym.v3.models. NOTE: a member without the required credit type is
# booked UNPAID rather than rejected — check payment_info if payment matters.
client.update_booking(events[0].event_id, {"member_id": 42, "presence": True})
client.cancel_booking(events[0].event_id, member_id=42, refund=False)

Note: occurrences of a recurring event share the same event_id and differ only in datetime_start — use event_id + datetime_start as the occurrence key.

Async

Both clients have async twins with identical surfaces:

from virtuagym import AsyncVirtuaGymClientV1

client = AsyncVirtuaGymClientV1(api_key="...", club_secret="...", club_id=12345)

async for page in client.members():
    ...
members = await client.all_members()

Error handling

from virtuagym import VirtuaGymApiError, VirtuaGymV3ApiError

try:
    client.member(999)
except VirtuaGymApiError as e:
    # v1: in-band API errors (reported with HTTP 200), real-HTTP-status
    # errors, and envelope failures.
    print(e.statuscode, e.statusmessage)  # e.g. 420 'Not found.'
  • VirtuaGymApiError (v1) — statuscode, statusmessage, optional errors payload.
  • VirtuaGymV3ApiError (v3) — real HTTP status in http_status, invalid field names in fields. On a 401 the client refreshes the token and retries once before raising.
  • pydantic.ValidationError — the response did not match the documented schema, naming the exact offending field.

Development

pip install -e .[dev]
pytest               # unit tests (offline, mocked HTTP)
ruff check . && ruff format --check . && mypy

# Smoke tests against the live API (read-only):
cp .env.example .env  # then fill in your credentials
pytest -m smoke

License

MIT

Download files

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

Source Distribution

virtuagym-1.0.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

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

virtuagym-1.0.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file virtuagym-1.0.1.tar.gz.

File metadata

  • Download URL: virtuagym-1.0.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for virtuagym-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ddd0eece46485515a3d37d73ca93bf4a44c1d36ce328cc6c47be7056c088bb02
MD5 cd5b5335d490364ea47d6184c189292b
BLAKE2b-256 b0b3d5316ed678b513bc7f86dd7657b651c19d05f6bfaf5af8fbd9b27d8e8de7

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtuagym-1.0.1.tar.gz:

Publisher: publish.yml on gold-development/virtuagym-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file virtuagym-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: virtuagym-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for virtuagym-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9499a068a76c8dea1c5c5e4bb948740d2e3e1a08c940c6c0053e7a116116627f
MD5 14186a3100273be9292ec16ae1d41c9b
BLAKE2b-256 10c09c479b0709f339ef662e203cb034054bbb928aceaa9b4d7397a55113b171

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtuagym-1.0.1-py3-none-any.whl:

Publisher: publish.yml on gold-development/virtuagym-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

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