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.1.tar.gz (80.8 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.1-py3-none-any.whl (179.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mgx-1.0.1.tar.gz
  • Upload date:
  • Size: 80.8 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.1.tar.gz
Algorithm Hash digest
SHA256 41dd49b2320b6978bd816edb38c5c6b82c77a487119a81eb1fa80c41570acada
MD5 ff2c504775f18958ecb64161fde18d9d
BLAKE2b-256 b12e30238969da445b203a62389395145ae13169587a540a2de2293b01b32e99

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgx-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: mgx-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 179.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1676c0d37b82e89065615a2ac83d5a0cc51713432b3241aba79619daaff2867
MD5 42858d4b5e9188da76a8f2962b059c4d
BLAKE2b-256 ef8da3f153a0cd9112ef1960c72052057aa69599f7dc5ae7fbbb0a7bf3a8e2eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgx-1.0.1-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