Skip to main content

ClickHouse backend

The DuckDB builder remains the source of truth. Build a DuckDB file with build_merged_duckdb, then upload its canonical tables into ClickHouse:

uv run python scripts/upload_clickhouse.py data/dbs_final/SmallMolecule.duckdb --database normalization

The upload shows a progress bar for each copied table; pass --no-progress to silence it.

Connection settings are read from .env with python-dotenv and use the official clickhouse-connect client. Set CH_HTTP, for example http://host:8123/normalization; CH_USER and CH_PASSWORD may be supplied separately and override URL credentials.

Use the ClickHouse backend from Python:

import asyncio

from norm_toolkit import ClickHouseNormalizer


async def main():
    normalizer = await ClickHouseNormalizer.create(database="normalization")
    result = await normalizer.normalize(["aspirin"], top_k=5)
    print(result)

    # Walk the SNOMEDCT_US Disease (disorder) hierarchy. Each ancestor is
    # returned once at its shortest graph distance; direct parents have depth 1.
    broader = await normalizer.get_broader_concepts(
        "UMLS:C0006142",
        max_depth=None,
        max_size=2000,
    )
    print([(concept.identifier, concept.depth) for concept in broader])

    await normalizer.aclose()


asyncio.run(main())

Disease hierarchy data is a graph rather than a strict tree. Upward traversal uses only SNOMEDCT_US is-a edges beneath Disease (disorder); it does not cross into other UMLS source vocabularies. Traversals deduplicate diamonds, terminate cycles, and keep the shortest depth for concepts reached by multiple paths. Use max_depth=None to continue to the disease root.

Normalizer instances keep a 10,000-item LRU cache. Repeated items skip string normalization, database lookup, enrichment, and hierarchy expansion; misses in a mixed batch are queried together and added to the cache. Synonyms and all result-affecting options are part of the cache key.

normalizer = await ClickHouseNormalizer.create(
    database="normalization",
    normalization_cache_size=50_000,  # 0 disables; None is unbounded
)

print(normalizer.normalization_cache_info())
normalizer.clear_normalization_cache()  # also use after refreshing backing tables

You can also pass a DSN in code:

normalizer = await ClickHouseNormalizer.create(
    dsn="http://host:8123/normalization",
    database="normalization",
)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

norm_toolkit-2.0.2.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

norm_toolkit-2.0.2-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

Details for the file norm_toolkit-2.0.2.tar.gz.

File metadata

  • Download URL: norm_toolkit-2.0.2.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for norm_toolkit-2.0.2.tar.gz
Algorithm Hash digest
SHA256 bbdd6ff0dd0d310d59cdb61df13a8eabb6d272b963ba6d08c2661011ef4d8664
MD5 d3e3f048b0486a7bf6cf432c2353425b
BLAKE2b-256 f4493235ba18966ea102e485d10309d521bd65f8ef13fc939e136befa51c89bc

See more details on using hashes here.

File details

Details for the file norm_toolkit-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: norm_toolkit-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 51.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for norm_toolkit-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 270b5dfb3fe65882560450f250249b421d40e47cdf0494e6ac2ee653f6e6c0d7
MD5 30698ab53bab0156568f56d15c077280
BLAKE2b-256 6d9844042d85557b406b8abb271f25ba599cccbe146d95f24fb9cf80f37e1cc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page