Skip to main content

MGX Enterprise API

Project description

mgx

Official Python client for the MGX Enterprise API.

pip install mgx

Quickstart

The ergonomic client lives in mgx.overlay:

import os
from mgx.overlay import MgxClient, MgxApiError

mgx = MgxClient(
    client_id=os.environ["MGX_CLIENT_ID"],
    client_secret=os.environ["MGX_CLIENT_SECRET"],
    scopes=["inventory.read", "market.read"],
    # base_url="https://dashboard.mgx.test/v1",  # for local development
)

# Auto-paginates the { items, limit, offset, next } envelope.
for lot in mgx.inventory.list(commodity="wheat", min_quantity=50):
    print(lot.id, lot.quantity_mt, lot.asking_price.amount if lot.asking_price else None)

Authentication

  • Client credentials (read-only data) — pass client_id + client_secret + scopes; the SDK acquires and refreshes the token for you.
  • Login with MGX (user-context: bids, trades, teams, cash bids, webhooks) — complete the authorization-code + PKCE flow, then pass the resulting access_token (and optionally refresh_token) to MgxClient.

Features

  • Resource namespacesinventory, market, bids, trades, teams, cash_bids, webhooks.
  • Auto-pagination — every list() returns a generator that follows next and yields items lazily.
  • Idempotencyinventory.place_bid() sends an Idempotency-Key automatically (pass idempotency_key= to override).
  • Typed errors — non-2xx responses raise MgxApiError with status, code, message, and field_errors.
try:
    bid = mgx.inventory.place_bid(
        "inv_3Kd9aZ",
        quantity_mt=50,
        price={"amount": 312.5},
        delivery={"from": "2026-08-01", "to": "2026-09-30"},
    )
except MgxApiError as e:
    print(e.status, e.code, e.message, e.field_errors)

Generated code

The mgx/ client (everything except mgx/overlay/) is generated from the OpenAPI spec; the ergonomic layer lives in mgx/overlay/. Do not hand-edit the generated modules — change the API spec and regenerate. See the mgx-sdks repo.

License

MIT

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

mgx-1.0.0.tar.gz (70.7 kB view details)

Uploaded Source

Built Distribution

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

mgx-1.0.0-py3-none-any.whl (152.7 kB view details)

Uploaded Python 3

File details

Details for the file mgx-1.0.0.tar.gz.

File metadata

  • Download URL: mgx-1.0.0.tar.gz
  • Upload date:
  • Size: 70.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mgx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9722eb877bff8b88cfdbcca7df48a43ea5f3ae7a253e43b56ce2b4691ed73f50
MD5 80d274451594546f0713adcbe969bcf9
BLAKE2b-256 be5e25e891a54d894326e557f3ddfd6c750b37241b3065a18e9e0e2b4a005c7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgx-1.0.0.tar.gz:

Publisher: release.yml on mygrainexchange/mgx-sdks

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

File details

Details for the file mgx-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mgx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 152.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mgx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 651a517c45c51f2bcf0fe6ffd08c53e94a1dd5b08ac7362b4c17d98d75721547
MD5 91c1ad104d46fef5e6dfbf8acac79de2
BLAKE2b-256 19fedf37b8647f852f02d1bfb5b318b29a69ed93f6f6c356daa40ef8c5003971

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgx-1.0.0-py3-none-any.whl:

Publisher: release.yml on mygrainexchange/mgx-sdks

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

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