Registry / science / xraydb

xraydb

JSON →
library4.5.8pypypi✓ verified 72d ago

XrayDB provides reference data for X-ray interactions with matter, including atomic scattering factors, X-ray absorption cross-sections, fluorescence yields, and more. Version 4.5.8 supports Python >=3.9. Release cadence is irregular, with occasional minor updates.

pip install xraydb
INSTALL
IMPORT
SIG · XRAYDB
X
xraydb
sciencepythonv4.5.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

XrayDB
from xraydb import XrayDB
Main class used for querying X-ray data.
f1_energies
from xraydb import f1_energies
Returns anomalous scattering factors f1 and f2 given element and energy.
atomic_density
from xraydb import atomic_density
Returns atomic density element.

Basic usage of XrayDB to fetch anomalous scattering factors and absorption cross-sections.

import os from xraydb import XrayDB # Use an API key if required (currently no key needed for local database) db = XrayDB(cache_dir=os.environ.get('XRAYDB_CACHE', '/tmp/xraydb_cache')) # Get anomalous scattering factors for iron at 7 keV energy = 7000 # eV f1, f2 = db.f1_energies('Fe', energy) print(f"f1 = {f1:.3f}, f2 = {f2:.3f}") # Get x-ray absorption cross-section for copper at 10 keV mu = db.mu('Cu', 10000) print(f"mu = {mu:.5e} cm^2/g")
Debug
Known issues
gotchaThe database is bundled with the package; a large download (~100 MB) occurs on first import or use. Ensure sufficient disk space and internet connection.
fix
None (expected behavior).  Alternatively, use system database by setting environment variables or installing separately.
affects: all
gotchaThe database download URL changed in version 4.5.0; older cached databases may cause errors until deleted. If you see "Database version mismatch" after upgrading, remove the cache directory (default ~/.xraydb).
fix
Delete the cache directory: rm -rf ~/.xraydb
affects: >=4.5.0, <4.6.0
deprecatedThe function `get_xraydata` was removed in version 4.0.0 without deprecation. Use `XrayDB` class methods instead.
fix
Use from xraydb import XrayDB; db = XrayDB(); db.mu('Fe', 7000) instead.
affects: >=4.0.0
gotchaThe database file is large (over 100 MB) and may cause slow first-time imports. On low-storage systems, import can fail with insufficient space.
fix
Set an alternative cache directory with XRAYDB_CACHE environment variable or pass cache_dir to XrayDB().
affects: all
Errors
Common errors & fixes
DatabaseError: Database version mismatch. Expected 4.5.0, got 4.4.0
Outdated cached database after upgrading xraydb.
fix
Delete the cache: rm -rf ~/.xraydb and re-run your script.
FileNotFoundError: [Errno 2] No such file or directory: '~/.xraydb/xraydb.sqlite'
Database has not been downloaded or cache directory is missing.
fix
Run your script again; the download will start automatically.  Alternatively, set XRAYDB_CACHE to a writable directory.
ImportError: cannot import name 'get_xraydata' from 'xraydb'
Function removed in xraydb 4.0.0.
fix
Use the XrayDB class: from xraydb import XrayDB; db = XrayDB(); results = db.mu(...)
ValueError: Element 'Uu' not found
Invalid element symbol passed to a function.
fix
Use valid element symbols e.g., 'Fe', 'Cu'.  Case-sensitive.
Upgrade
Version history
4.5.8latest on PyPI · released Jul 18, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
32
Resources
xraydb — pip install xraydb · libregistry