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
HubMixinto 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:
- Per call:
MyTokenizer.load_from_hub(..., cache_dir="/data/cache") - Per class:
MyTokenizer.CACHE_DIR = Path("/data/cache") - Globally, in code:
dlmhub.config.set_cache_dir("/data/cache") - Globally, via environment:
DLMHUB_CACHE_DIR=/data/cache - 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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dlmhub-0.1.0.tar.gz.
File metadata
- Download URL: dlmhub-0.1.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1e12e0967c045614aa25618f2e7d8f76d2b4a80edd6ac5480c2ac499eb62674
|
|
| MD5 |
ffca4b2c50c4904cd06e1b2eb792d6f7
|
|
| BLAKE2b-256 |
28d2c7c5437da2040546026e88772691efe76a1fe5c426d02190d504b5d14e79
|
Provenance
The following attestation bundles were made for dlmhub-0.1.0.tar.gz:
Publisher:
main.yml on kariminf/dlmhub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlmhub-0.1.0.tar.gz -
Subject digest:
f1e12e0967c045614aa25618f2e7d8f76d2b4a80edd6ac5480c2ac499eb62674 - Sigstore transparency entry: 2724287867
- Sigstore integration time:
-
Permalink:
kariminf/dlmhub@17b0dbc7af814fa2562046af02687c9b7a407784 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kariminf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@17b0dbc7af814fa2562046af02687c9b7a407784 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dlmhub-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dlmhub-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea501cee1e165b1e9e857e7254695347e87cea37223ccda26eb914a9200633b1
|
|
| MD5 |
82784786e912461d25d965165b65b6f1
|
|
| BLAKE2b-256 |
c5d65bc5e8a128eec303b9c91721ead0d9340ad8d3489ebe0795519b10f7251f
|
Provenance
The following attestation bundles were made for dlmhub-0.1.0-py3-none-any.whl:
Publisher:
main.yml on kariminf/dlmhub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlmhub-0.1.0-py3-none-any.whl -
Subject digest:
ea501cee1e165b1e9e857e7254695347e87cea37223ccda26eb914a9200633b1 - Sigstore transparency entry: 2724288153
- Sigstore integration time:
-
Permalink:
kariminf/dlmhub@17b0dbc7af814fa2562046af02687c9b7a407784 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kariminf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@17b0dbc7af814fa2562046af02687c9b7a407784 -
Trigger Event:
workflow_dispatch
-
Statement type: