Skip to main content

dlmhub

A small, provider-agnostic model hub for Python libraries. dlmhub gives your users a MyClass.load_from_hub("org/model") API without hard-wiring your project to Hugging Face Hub (or any single provider).

Why

Many libraries want "download my pretrained files, cache them locally, load them" behavior, but end up tightly coupled to huggingface_hub. dlmhub extracts that pattern into a standalone, dependency-light package where:

  • Providers are pluggable. Hugging Face and GitHub releases ship as built-ins; register your own (S3, a private server, git-lfs, ...) with a few lines.
  • The cache directory is fully parametrable. Set it globally, per class, or per call — whichever fits your app.
  • The mixin is the only requirement. Add HubMixin to any class, declare the files it needs, implement how to build an instance from them, and you're done.

Install

pip install -e .            # from a local checkout
# or, once published:
pip install dlmhub

Quickstart

from dlmhub import HubMixin

class MyTokenizer(HubMixin):
    files = ["vocab.json", "merges.txt"]

    @classmethod
    def _load_from_files(cls, local_files, **kwargs):
        # local_files: {"vocab.json": Path(...), "merges.txt": Path(...)}
        ...
        return cls(...)

tok = MyTokenizer.load_from_hub("org/model")                  # Hugging Face by default
tok = MyTokenizer.load_from_hub("org/repo", provider="github") # GitHub releases
tok = MyTokenizer.load_from_hub("org/model", variant="fp16")   # variant-prefixed files
tok = MyTokenizer.load_from_hub("org/model", token="hf_...")   # private/gated repos

Configuring the cache directory

Resolution order, highest priority first:

  1. Per call: MyTokenizer.load_from_hub(..., cache_dir="/data/cache")
  2. Per class: MyTokenizer.CACHE_DIR = Path("/data/cache")
  3. Globally, in code: dlmhub.config.set_cache_dir("/data/cache")
  4. Globally, via environment: DLMHUB_CACHE_DIR=/data/cache
  5. Built-in default: ~/.cache/dlmhub
import dlmhub
dlmhub.config.set_cache_dir("/data/model_cache")

Adding a custom provider

from dlmhub.providers import Provider, default_registry

# Simple case: just a URL template with {model} and {file} placeholders.
default_registry.register(Provider(
    name="my-s3",
    url_pattern="https://my-bucket.s3.amazonaws.com/{model}/{file}",
))

# Full control: supply your own download logic (auth, SDKs, checksums...).
def _download_from_internal_server(model, file, dest_path, headers, **kwargs):
    ...  # write bytes to dest_path yourself

default_registry.register(Provider(
    name="internal",
    download_fn=_download_from_internal_server,
))

Need full isolation instead of touching the shared registry? Create your own ProviderRegistry() and assign it to MyTokenizer.PROVIDER_REGISTRY.

Compact hub-path strings

For CLIs/config files, a "provider:model[:variant]" string can be parsed with:

from dlmhub import process_hub_path

process_hub_path("huggingface:org/model:fp16")
# {"provider": "huggingface", "model": "org/model", "variant": "fp16"}

Project layout

src/dlmhub/
    __init__.py     public API surface
    config.py       global, overridable configuration (cache dir, ...)
    providers.py    Provider / ProviderRegistry, built-in HF + GitHub providers
    hub.py          HubMixin: load_from_hub() and download orchestration
    hubpath.py      "provider:model:variant" string parsing
    fileutils.py    small filesystem helpers (list files/subfolders, read lines)
    exceptions.py   DlmHubError and friends
tests/

License

Copyright (C) 2026 Abdelkrime Aries

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Metadata

Release files for dlmhub 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 dlmhub 0.1.0
File Size Uploaded Provenance Actions
dlmhub-0.1.0.tar.gz 15.9 kB With provenance Details for dlmhub-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 34.0 kB

Release files / dlmhub-0.1.0.tar.gz

Download URL dlmhub-0.1.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f1e12e0967c045614aa25618f2e7d8f76d2b4a80edd6ac5480c2ac499eb62674
BLAKE2b-256 checksum
How to use checksums
28d2c7c5437da2040546026e88772691efe76a1fe5c426d02190d504b5d14e79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 5, 2026.

Transparency log

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

Download URL dlmhub-0.1.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea501cee1e165b1e9e857e7254695347e87cea37223ccda26eb914a9200633b1
BLAKE2b-256 checksum
How to use checksums
c5d65bc5e8a128eec303b9c91721ead0d9340ad8d3489ebe0795519b10f7251f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 5, 2026.

Transparency log

Security for dlmhub 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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dlmhub-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 Sep 5, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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