MaterialsGalaxy SDK
Python client for the MaterialsGalaxy API.
Install
pip install materialsgalaxy-api
For local development from this repository:
cd sdk
uv sync --dev
Authentication
Pass an API key directly:
from materialsgalaxy import MGClient
with MGClient(api_key="sk-...", base_url="https://materialsgalaxy.iphy.ac.cn/api/v1") as mg:
structure = mg.materials.get_structure("mg-1")
Or set MATERIALSGALAXY_API_KEY:
export MATERIALSGALAXY_API_KEY="sk-..."
Search Materials
search() returns a PagedSummary model. Use fields to request only the fields you need.
from materialsgalaxy import MGClient
with MGClient(base_url="https://materialsgalaxy.iphy.ac.cn/api/v1") as mg:
page = mg.materials.search(
elements=["Si", "O"],
fields=["mg_id", "reduced_formula", "properties.band_gap"],
page_size=10,
)
print(page.total)
print(page.data[0].mg_id)
print(page.data[0].properties)
List available summary data sources before filtering by source:
with MGClient() as mg:
sources = mg.materials.list_data_sources()
for source in sources:
print(source.source, source.count)
Detail Endpoints
with MGClient(api_key="sk-...") as mg:
summary = mg.materials.get_summary("mg-1")
structure = mg.materials.get_structure("mg-1")
growth = mg.materials.get_single_crystal_growth("mg-1")
electronic = mg.materials.get_electronic_structure("mg-1", soc=False)
topology = mg.materials.get_topology("mg-1", soc=False)
phonons = mg.materials.get_phonons("mg-1")
ferroelectric = mg.materials.get_ferroelectric("mg-1")
nonlinear = mg.materials.get_nonlinear_optical("mg-1")
print(structure.symmetry.symbol if structure else None)
print(topology.topo_class if topology else None)
Search Then Fetch Details
with MGClient(api_key="sk-...") as mg:
page = mg.materials.search(
formula="SiO2",
fields=["mg_id", "reduced_formula"],
page_size=5,
)
structures = mg.materials.get_structures([item.mg_id for item in page.data if item.mg_id])
for structure in structures:
print(structure.mg_id, structure.lattice.volume if structure else None)
Use iter_search() to page through all matches:
with MGClient(api_key="sk-...") as mg:
for material in mg.materials.iter_search(
elements=["Si", "O"],
fields=["mg_id", "reduced_formula"],
page_size=100,
):
print(material.mg_id, material.reduced_formula)
Returned Models
The SDK returns Pydantic models that mirror the public API contract:
PagedSummaryDataSourceSummaryCrystalStructureSingleCrystalGrowthElectronicStructureTopologicalPropertiesTopologicalPhononFerroelectricNonlinearOpticalProperties
Summary fields are optional because fields=[...] can request partial summary payloads.
Errors
from materialsgalaxy import MGClient
from materialsgalaxy.exceptions import MaterialsGalaxyAuthenticationError, MaterialsGalaxyHTTPError
try:
with MGClient(api_key="sk-...") as mg:
mg.materials.get_structure("mg-1")
except MaterialsGalaxyAuthenticationError:
print("Invalid or revoked API key")
except MaterialsGalaxyHTTPError as exc:
print(exc.status_code, exc.detail)
Metadata
Release files for materialsgalaxy-api 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| materialsgalaxy_api-0.1.2.tar.gz | 30.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| materialsgalaxy_api-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.4 kB
Release files / materialsgalaxy_api-0.1.2.tar.gz
| Download URL | materialsgalaxy_api-0.1.2.tar.gz |
|---|---|
| Size | 30.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
435b49a895bba611d06a2d8d1ae0637b267737efb5a12c912d1e384cf539102e
|
|
BLAKE2b-256 checksum How to use checksums |
3cc61904af39939b13d11403851be4fdf8fc7ed48f7a6531d3c2eed56b2be0b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CentOS Linux","version":"7","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / materialsgalaxy_api-0.1.2-py3-none-any.whl
| Download URL | materialsgalaxy_api-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
105f6d5cd644c7a75e691044c23a6579cce91ad7a1d04ef3c4bd5e0624cfa50a
|
|
BLAKE2b-256 checksum How to use checksums |
fb530148fdb3f9033a12bb25efa0b1d6f8fa7fdb77afb704a699df5875c1ce6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CentOS Linux","version":"7","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for materialsgalaxy-api 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.