Skip to main content

raxtik-source-faers

CI codecov License: AGPL-3.0

Official FDA FAERS/AERS data source connector, signature resolver, and canonical extractor for raxtik-etl.


🏛 Overview

raxtik-source-faers is an independent plugin that implements the SourceAdapter protocol for raxtik-etl. It isolates all FDA-specific archive formats, legacy ASCII quirks, and historical schema evolution from the canonical data platform:

  • Fail-closed signature resolution: Accurately classifies releases into S1, S2, or S3 schemas.
  • Raw ASCII extract staging: Safely parses $-delimited text files, embedded line-breaks, and historical field aliases.
  • Reference codelists: Embedded clinical lookup tables for FDA CDER routes, dosage forms, and reporter roles.
  • Zero-core coupling: Registers via Python standard entry points without requiring any FAERS-specific logic inside raxtik-etl.

🔍 Historical Signatures Handled

Signature Date Range Primary Keys Distinguishing Features
S1 2004Q1 – 2012Q3 ISR, CASE Legacy AERS: FOLL_SEQ, GNDR_COD. Missing modern columns (PROD_AI, AUTH_NUM).
S2 2012Q4 – 2014Q2 PRIMARYID, CASEID Migration Era: Transitional columns (gndr_cod, lot_nbr, outc_code).
S3 2014Q3 – Present PRIMARYID, CASEID Modern FAERS/AEMS: SEX, PROD_AI, AUTH_NUM, LIT_REF, DRUG_REC_ACT.

Signature detection is fail-closed: any unrecognized or malformed archive raises an explicit ValueError rather than silently defaulting to modern schemas.


🏛️ Canonical Data Model & Schema Mapping

The raw FDA ASCII files (DEMO, DRUG, REAC, OUTC, INDI, THER, RPSR) are projected into the unified canonical star-schema:

Entity Relationships & Composite Keys

Table Entity / Domain Primary Key (Composite) Foreign Key Relationship Description
demo Case Submissions & Demographics primary_id (Root submission table) Patient age in decimal years, weight in kg, sex, country, receipt date.
drug Drug Products & Regimens (primary_id, drug_seq) primary_id → demo.primary_id Reported brand name, active substance, route, form, role code (PS, SS, C, I).
reac Adverse Reactions (primary_id, reported_reaction_term) primary_id → demo.primary_id MedDRA Preferred Terms (PT) describing adverse events.
outc Patient Outcomes (primary_id, outc_code) primary_id → demo.primary_id Clinical outcomes: Death (DE), Hospitalization (HO), Disability (DS), etc.
indi Therapy Indications (primary_id, indi_drug_seq, reported_indication_term) (primary_id, indi_drug_seq) → drug(primary_id, drug_seq) Medical conditions for which medications were prescribed.
ther Therapy Timelines (primary_id, dsg_drug_seq) (primary_id, dsg_drug_seq) → drug(primary_id, drug_seq) Therapy start date, end date, and duration in days.
rpsr Report Sources (primary_id, rpsr_code) primary_id → demo.primary_id Reporting channel: Health Professional (HP), Consumer (CSM), Study (SDY), etc.
cases Authoritative Deduplicated View case_id Derived from demo Precomputed deterministic resolution to latest report version per case_id.

📖 Visual Entity-Relationship Diagram:


📦 Installation

Install alongside raxtik-etl:

pip install raxtik-source-faers raxtik-etl

Once installed, raxtik-etl automatically discovers the FAERS connector and provides the specialized FAERS dataset client.


🚀 Usage

1. Direct Hugging Face Loading & Streaming

Query precompiled quarterly packages from 2004Q1 through 2026Q3:

from raxtik_etl import FAERS

# 1. Default (Fastest): Downloads once, caches locally, queries in milliseconds
with FAERS.from_hf("2024Q1") as faers:
    cases = faers.cases(limit=100)
    print(cases)

# 2. Remote Streaming (No Full Dataset Download): Streams directly over HTTPS
with FAERS.from_hf("2024Q1", remote=True) as faers:
    cases = faers.cases(limit=100)
    print(cases)

# 3. Quarter-Scoped Silver Tier (winning cases in 2024Q1 as of 2025Q4 + full case timeline)
with FAERS.from_hf("2024Q1", tier="silver", remote=True, as_of_period="2025Q4") as faers:
    cases = faers.cases(limit=100)
    timeline = faers.case_timeline(str(cases["case_id"][0]))
    print(timeline)

2. Remote Querying via DuckDB (No Full Dataset Download)

Query precompiled datasets on Hugging Face Hub over HTTPS without downloading full files to disk.

Option A: Remote DuckDB ATTACH (Single File URL, Full Schema & Views)

import duckdb

con = duckdb.connect()
# httpfs is DuckDB's native C++ extension (no pip install required)
con.execute("INSTALL httpfs; LOAD httpfs;")

# 1 single URL attaches all 7 tables and the precomputed cases view
db_url = "https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.duckdb"
con.execute(f"ATTACH '{db_url}' AS faers (READ_ONLY);")

con.execute("""
    SELECT d.reported_drug_name, COUNT(*) AS report_count
    FROM faers.drug d
    JOIN faers.reac r ON d.primary_id = r.primary_id
    WHERE d.role_code = 'PS' AND r.reported_reaction_term = 'Myocardial infarction'
    GROUP BY d.reported_drug_name ORDER BY report_count DESC LIMIT 5;
""").show()

Note: Initial ATTACH takes ~10s to load catalog metadata over HTTP, after which subsequent queries execute directly.

Option B: Remote Parquet Scanning (Column Range Requests)

import duckdb

con = duckdb.connect()
con.execute("INSTALL httpfs; LOAD httpfs;")

con.execute("""
    SELECT d.reported_drug_name, COUNT(*) AS report_count
    FROM 'https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.parquet/drug.parquet' d
    JOIN 'https://huggingface.co/datasets/raxtik-org/faers-safety-database/resolve/main/bronze/2024/faers_2024Q1.parquet/reac.parquet' r
      ON d.primary_id = r.primary_id
    WHERE d.role_code = 'PS' AND r.reported_reaction_term = 'Myocardial infarction'
    GROUP BY d.reported_drug_name ORDER BY report_count DESC LIMIT 5;
""").show()

3. Download Quarterly FDA Archives

from raxtik_source_faers import download_quarterly_archive

# Downloads and verifies official quarterly FDA archive zip
zip_path = download_quarterly_archive(year=2024, quarter=1, dest_dir="data/raw")
print(f"Downloaded to {zip_path}")

4. Extract into Canonical DuckDB via Adapter

import duckdb
from pathlib import Path
from raxtik_etl.sources.protocol import SourceArtifact
from raxtik_source_faers import FAERSAdapter

con = duckdb.connect("my_database.duckdb")
adapter = FAERSAdapter()

artifact = SourceArtifact(path=Path("data/raw/faers_ascii_2024q1.zip"), release="2024Q1")

result = adapter.extract_and_load(con, artifact)
print(f"Extracted {result.row_counts['demo']} reports under signature {result.signature_id}")

👥 Contributors

See CONTRIBUTORS.md for all project contributors.


📄 License

Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).

Metadata

Release files for raxtik-source-faers 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for raxtik-source-faers 0.1.0
File Size Uploaded Provenance Actions
raxtik_source_faers-0.1.0.tar.gz 59.9 kB With provenance Details for raxtik_source_faers-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for raxtik-source-faers 0.1.0
File Interpreter ABI Platform Actions
raxtik_source_faers-0.1.0-py3-none-any.whl Python 3 none any Details for raxtik_source_faers-0.1.0-py3-none-any.whl

Total release size: 116.2 kB

Release files / raxtik_source_faers-0.1.0.tar.gz

Download URL raxtik_source_faers-0.1.0.tar.gz
Size 59.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5d5faa1e0fde46255530ac4c8046b7841517d2619070ba8fcb32503564334068
BLAKE2b-256 checksum
How to use checksums
ee489ee039d0c9d0f8e2b74811902659ae52845962f8b4ad336aa1ee648e87b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / raxtik_source_faers-0.1.0-py3-none-any.whl

Download URL raxtik_source_faers-0.1.0-py3-none-any.whl
Size 56.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
995a17aeda29266d8ce3d29d322b7a3bd99456e124ee14bb861fcebfd23ff782
BLAKE2b-256 checksum
How to use checksums
b95ef9439ff1e18c9dda5ff4c6cc98fb2167db41666ea4cd57c97f0d95f44b2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for raxtik-source-faers 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for raxtik_source_faers-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page