By Sarah Stewart, University of Edinburgh, April-June 2026.
Contact: s.v.stewart@ed.ac.uk
Scripts used to automate the querying and retrieval of information from Mindat.org via the API. The scripts were originally created to search for Scottish localities, but can be easily modified for other localities. See the individual help pages for information on this.
The main aims of these scripts are to:
- match a mineral list to standardised Mindat mineral records
- retrieve general mineral information such as formula and classification
- retrieve occurrence and locality information
- reorganise Mindat locality strings into more structured location fields
- produce a deduplicated list of localities for later matching and manual review
These scripts are intended to be run in sequence.
- Quick Start
- Scripts included
- Recommended workflow
- Script outputs
- Software requirements
- Getting an API key
- Customization
- Troubleshooting
-
Install dependencies:
pip install -r requirements.txt
-
Create a file called
API_key.txtin the same directory as the scripts, containing your Mindat API key -
Prepare your mineral list as a CSV file with mineral names in the first column
-
Run the scripts in order:
python fetch_mindat_mineral_info.py python fetch_mindat_localities.py python parse_mindat_localities.py
Shared helper used by other scripts to retrieve info from Mindat.
Fetches general mineral information from Mindat for a list of mineral names.
Retrieves occurrence and locality information from Mindat for the input minerals.
Splits Mindat free-text locality strings into structured fields and creates a deduplicated locality list.
- Prepare mineral list: Create a CSV with mineral names in the first column
- Fetch mineral info: Run
fetch_mindat_mineral_info.pyto get standardized mineral records - Fetch localities: Run
fetch_mindat_localities.pyto get occurrence data - Parse localities: Run
parse_mindat_localities.pyto structure the locality data - Review outputs: Check the generated CSV files in Excel or similar
The output names are based on a Scottish locality search.
| File | Description |
|---|---|
Scotland_minerals.csv |
Clean Mindat mineral reference table with IDs, formulae, and classifications. |
Scotland_minerals_rarity_summary.csv |
Scottish occurrence summary for the input minerals. |
Scotland_minerals_localities.csv |
Scottish mineral-locality output from Mindat. |
Scotland_minerals_localities_separated.csv |
Parsed version of the Mindat locality table with structured place fields. |
mindat_unique_locations.csv |
Deduplicated list of Mindat localities for later review and matching. |
- Python 3.8 or higher
- Mindat API key (free, request from https://www.mindat.org/api.php)
- Dependencies listed in
requirements.txt
- Create a free account on Mindat.org
- Visit the API page
- Request an API key
- Save the key in a file called
API_key.txtin the scripts directory
To search for localities in a different region:
- Find the Mindat ID for your target locality (e.g., Scotland = 14091)
- In
fetch_mindat_localities.py, update:LOC_NAME = "Your Region Name" LOC_ID = 12345 # Your locality ID
The matching logic in fetch_mindat_mineral_info.py can be adjusted to:
- Change the order of matching preferences
- Add custom synonym handling
- Adjust scoring for different match types
To fetch additional data from Mindat, modify the GEOMATERIAL_FIELDS or LOCALITY_FIELDS constants in the respective scripts.
- Ensure
API_key.txtis in the same directory as the scripts - Check that the key is valid and not expired
- Verify the key has no extra whitespace
- The scripts include built-in rate limiting (0.05s between requests)
- If you encounter rate limit errors, increase the
polite_sleepvalue
- Check the
match_typecolumn in the output - Minerals with
not_foundmay need manual review or alternative naming
- Mindat locality strings are not always consistent
- Review
mindat_unique_locations.csvfor anomalies - Add new county aliases to
COUNTY_ALIASESinparse_mindat_localities.py
These materials are made freely available, and are licensed under a CC-BY 4.0 license.