Authentication and Environment
This section explains how to authenticate your Mathpix Python SDK client and configure environment variables for secure usage.
Authentication Methods
You can authenticate the
MathpixClient
in several ways. The client prioritizes credentials in the following order:- Credentials passed directly as arguments.
- Credentials stored in the
~/.mpx/config
file. - Credentials defined in
.env
orlocal.env
files. - System environment variables.
Using a Config File (~/.mpx/config
)
Create a configuration file at
~/.mpx/config
with the following content:MATHPIX_APP_ID=your-app-id
MATHPIX_APP_KEY=your-app-key
MATHPIX_URL=https://api.mathpix.com # Optional
The client will automatically detect and use these credentials.
Using Environment Variables
Alternatively, you can define environment variables in
.env
or local.env
files in your project directory:MATHPIX_APP_ID=your-app-id
MATHPIX_APP_KEY=your-app-key
MATHPIX_URL=https://api.mathpix.com # Optional
Passing Credentials Directly
You can also pass credentials directly when initializing the
MathpixClient
:from mpxpy.mathpix_client import MathpixClient
client = MathpixClient(
app_id="your-app-id",
app_key="your-app-key"
)
Credentials passed directly when initializing the client will override any environment-based settings.
Default API Endpoint
The default API endpoint is
You can override this endpoint if needed by setting
https://api.mathpix.com.
You can override this endpoint if needed by setting
MATHPIX_URL
in the environment variables or passing it to the client: client = MathpixClient(
app_id="your-app-id",
app_key="your-app-key",
api_base_url="https://custom-api.mathpix.com"
)
Highlights:
- Smooth logical order
- No heavy headers for notes
- Consistent tone with previous sections
- Ready for Markdown rendering and Doc generation