hf2ollama-python-cli-tool 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. hf2ollama_python_cli_tool-1.0.0/.github/workflows/publish.yml +52 -0
  2. hf2ollama_python_cli_tool-1.0.0/.gitignore +52 -0
  3. hf2ollama_python_cli_tool-1.0.0/LICENSE +21 -0
  4. hf2ollama_python_cli_tool-1.0.0/PKG-INFO +200 -0
  5. hf2ollama_python_cli_tool-1.0.0/README.md +170 -0
  6. hf2ollama_python_cli_tool-1.0.0/pyproject.toml +59 -0
  7. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/__init__.py +3 -0
  8. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/cli.py +329 -0
  9. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/core/__init__.py +1 -0
  10. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/core/config.py +73 -0
  11. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/core/ollama.py +137 -0
  12. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/hf/__init__.py +1 -0
  13. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/hf/alt_download.py +78 -0
  14. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/hf/api.py +197 -0
  15. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/hf/download.py +121 -0
  16. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/modelfile/__init__.py +1 -0
  17. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/modelfile/generator.py +90 -0
  18. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/modelfile/templates.py +134 -0
  19. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/network/__init__.py +1 -0
  20. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/network/detect.py +58 -0
  21. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/network/ssl_fix.py +76 -0
  22. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/scripts/HfDownload.ps1 +221 -0
  23. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/utils/__init__.py +1 -0
  24. hf2ollama_python_cli_tool-1.0.0/src/hf2ollama/utils/vram.py +65 -0
  25. hf2ollama_python_cli_tool-1.0.0/tests/__init__.py +0 -0
  26. hf2ollama_python_cli_tool-1.0.0/tests/test_modelfile.py +90 -0
@@ -0,0 +1,52 @@
1
+ name: Publish to PyPI
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ name: Build distribution
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v6
12
+ with:
13
+ persist-credentials: false
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v6
17
+ with:
18
+ python-version: "3.x"
19
+
20
+ - name: Install build tools
21
+ run: python3 -m pip install build --user
22
+
23
+ - name: Build wheel and sdist
24
+ run: python3 -m build
25
+
26
+ - name: Store distribution packages
27
+ uses: actions/upload-artifact@v5
28
+ with:
29
+ name: python-package-distributions
30
+ path: dist/
31
+
32
+ publish-to-pypi:
33
+ name: Publish to PyPI
34
+ if: startsWith(github.ref, 'refs/tags/')
35
+ needs:
36
+ - build
37
+ runs-on: ubuntu-latest
38
+ environment:
39
+ name: pypi
40
+ url: https://pypi.org/p/hf2ollama-python-cli-tool
41
+ permissions:
42
+ id-token: write
43
+
44
+ steps:
45
+ - name: Download distributions
46
+ uses: actions/download-artifact@v6
47
+ with:
48
+ name: python-package-distributions
49
+ path: dist/
50
+
51
+ - name: Publish to PyPI
52
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,52 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ *.egg
7
+ dist/
8
+ build/
9
+ .eggs/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Testing
17
+ .pytest_cache/
18
+ .coverage
19
+ htmlcov/
20
+ .mypy_cache/
21
+ .ruff_cache/
22
+
23
+ # IDE
24
+ .vscode/
25
+ .idea/
26
+ *.swp
27
+ *.swo
28
+
29
+ # OS
30
+ .DS_Store
31
+ Thumbs.db
32
+
33
+ # Environment
34
+ .env
35
+ .env.local
36
+
37
+ # Model files (large binaries)
38
+ *.gguf
39
+ /Modelfile
40
+
41
+ # Development context
42
+ .claude/
43
+ CLAUDE.md
44
+ Plan.md
45
+ pyrightconfig.json
46
+ linkedin-post.md
47
+
48
+ # Root-level PowerShell working copies
49
+ /ConvertToOllama.ps1
50
+ /HfDownload.ps1
51
+ /ollama-pull.ps1
52
+ /DownloadAndImport.ps1
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tanmoy Dutta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.5
2
+ Name: hf2ollama-python-cli-tool
3
+ Version: 1.0.0
4
+ Summary: Search, download, and import HuggingFace GGUF models into Ollama
5
+ Project-URL: Repository, https://github.com/rs2pydev/hf2ollama-python-cli-tool
6
+ Author: Tanmoy Dutta
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: gguf,huggingface,llm,model-management,ollama
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: certifi
21
+ Requires-Dist: click>=8.0
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: rich>=13.0
24
+ Requires-Dist: truststore>=0.9
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0; extra == 'dev'
27
+ Requires-Dist: respx>=0.21; extra == 'dev'
28
+ Requires-Dist: ruff>=0.4; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # hf2ollama
32
+
33
+ A Python CLI tool that searches, downloads, and imports HuggingFace GGUF models into Ollama. Handles model discovery, quantization selection, automatic Modelfile generation, and resumable downloads.
34
+
35
+ ## What it does
36
+
37
+ `ollama pull` only works with models hosted on the Ollama registry. Most open-weight GGUF models live on HuggingFace. This tool bridges that gap: search HuggingFace for GGUF repos, pick a quantization, download the file, auto-generate the correct Modelfile with chat template and stop tokens, and import into Ollama - all in one command.
38
+
39
+ It also handles a common Python SSL issue where `certifi` (the default CA bundle) doesn't include certificates from the operating system's trust store. The `--ssl-fix` flag exports the OS certificate store and configures Python to use it.
40
+
41
+ ## Installation
42
+
43
+ Works on Windows, macOS, and Linux. Requires Python 3.10+.
44
+
45
+ ```shell
46
+ pip install hf2ollama
47
+ ```
48
+
49
+ From source:
50
+
51
+ ```shell
52
+ git clone https://github.com/rs2pydev/hf2ollama-python-cli-tool.git
53
+ cd hf2ollama-python-cli-tool
54
+ pip install -e ".[dev]"
55
+ ```
56
+
57
+ ## Quick start
58
+
59
+ ```shell
60
+ # Search for models
61
+ hf2ollama search "qwen 7b gguf"
62
+
63
+ # See available quantizations and file sizes
64
+ hf2ollama list-files bartowski/Qwen2.5-Coder-7B-Instruct-GGUF
65
+
66
+ # Download and import into Ollama
67
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --quant Q4_K_M
68
+
69
+ # Fix Python SSL certificate issues if downloads fail
70
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --ssl-fix
71
+
72
+ # Use alternative download method (Windows, PowerShell 7 required)
73
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --alt-download
74
+ ```
75
+
76
+ ## Commands
77
+
78
+ ### pull
79
+
80
+ Download a GGUF model from HuggingFace and import into Ollama.
81
+
82
+ ```shell
83
+ hf2ollama pull <repo> [--quant Q4_K_M] [--name my-model] [--keep-gguf] [--ssl-fix] [--alt-download]
84
+ ```
85
+
86
+ Options:
87
+
88
+ - `--quant` / `-q` - Quantization level (Q2_K, Q3_K_M, Q4_K_M, Q5_K_M, Q6_K, Q8_0). Default: Q4_K_M.
89
+ - `--name` / `-n` - Ollama model name. Auto-generated from filename if not specified.
90
+ - `--keep-gguf` - Keep the GGUF file after importing into Ollama.
91
+ - `--ssl-fix` - Use OS certificate store instead of Python's default CA bundle.
92
+ - `--alt-download` - Use alternative PowerShell-based download method (Windows only, requires PowerShell 7).
93
+
94
+ The tool auto-detects the model family from the filename and generates the correct Modelfile with chat template and stop tokens.
95
+
96
+ ### search
97
+
98
+ Search HuggingFace for GGUF model repositories.
99
+
100
+ ```shell
101
+ hf2ollama search "llama 70b" --limit 20 --sort downloads
102
+ ```
103
+
104
+ ### list-files
105
+
106
+ Show available GGUF files in a repository with their sizes.
107
+
108
+ ```shell
109
+ hf2ollama list-files bartowski/Qwen2.5-Coder-7B-Instruct-GGUF
110
+ ```
111
+
112
+ ### list
113
+
114
+ List locally installed Ollama models.
115
+
116
+ ```shell
117
+ hf2ollama list
118
+ ```
119
+
120
+ ### remove
121
+
122
+ Delete an Ollama model.
123
+
124
+ ```shell
125
+ hf2ollama remove my-model:q4_k_m
126
+ ```
127
+
128
+ ### info
129
+
130
+ Show details about an installed Ollama model.
131
+
132
+ ```shell
133
+ hf2ollama info my-model:q4_k_m
134
+ ```
135
+
136
+ ### recommend
137
+
138
+ Recommend quantization based on your GPU VRAM and model size.
139
+
140
+ ```shell
141
+ # Auto-detect GPU VRAM
142
+ hf2ollama recommend --params 7
143
+
144
+ # Specify VRAM manually
145
+ hf2ollama recommend --params 70 --vram 24
146
+ ```
147
+
148
+ ### network-check
149
+
150
+ Check whether HuggingFace is reachable and whether SSL certificates are configured correctly.
151
+
152
+ ```shell
153
+ hf2ollama network-check
154
+ ```
155
+
156
+ ## Supported model families
157
+
158
+ The tool auto-detects model families from GGUF filenames and generates the correct Ollama Modelfile:
159
+
160
+ - Llama 3 / 3.1 / 3.2 / 3.3 / 4
161
+ - Gemma (2, 3, 4)
162
+ - Qwen (2, 2.5, 3)
163
+ - Mistral / Mixtral
164
+ - Phi (3, 4)
165
+ - DeepSeek (R1, V3)
166
+ - Granite
167
+ - Command-R
168
+ - ChatML (fallback for unrecognized models)
169
+
170
+ ## Supported quantizations
171
+
172
+ Q2_K, Q3_K_M, Q4_K_M (default), Q5_K_M, Q6_K, Q8_0
173
+
174
+ ## Configuration
175
+
176
+ Persistent config is stored in `~/.hf2ollama/config.toml`:
177
+
178
+ ```toml
179
+ download_dir = "C:/Users/you/.hf2ollama/downloads"
180
+ default_quant = "Q4_K_M"
181
+ hf_token = "hf_xxxxx"
182
+ ```
183
+
184
+ ## Requirements
185
+
186
+ - Python 3.10+
187
+ - Ollama installed locally
188
+ - For `--alt-download`: Windows + PowerShell 7
189
+
190
+ ## Dependencies
191
+
192
+ - click - CLI framework
193
+ - httpx - HTTP client with resumable downloads
194
+ - rich - Terminal tables and progress bars
195
+ - truststore - OS certificate store access
196
+ - certifi - Public CA bundle
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,170 @@
1
+ # hf2ollama
2
+
3
+ A Python CLI tool that searches, downloads, and imports HuggingFace GGUF models into Ollama. Handles model discovery, quantization selection, automatic Modelfile generation, and resumable downloads.
4
+
5
+ ## What it does
6
+
7
+ `ollama pull` only works with models hosted on the Ollama registry. Most open-weight GGUF models live on HuggingFace. This tool bridges that gap: search HuggingFace for GGUF repos, pick a quantization, download the file, auto-generate the correct Modelfile with chat template and stop tokens, and import into Ollama - all in one command.
8
+
9
+ It also handles a common Python SSL issue where `certifi` (the default CA bundle) doesn't include certificates from the operating system's trust store. The `--ssl-fix` flag exports the OS certificate store and configures Python to use it.
10
+
11
+ ## Installation
12
+
13
+ Works on Windows, macOS, and Linux. Requires Python 3.10+.
14
+
15
+ ```shell
16
+ pip install hf2ollama
17
+ ```
18
+
19
+ From source:
20
+
21
+ ```shell
22
+ git clone https://github.com/rs2pydev/hf2ollama-python-cli-tool.git
23
+ cd hf2ollama-python-cli-tool
24
+ pip install -e ".[dev]"
25
+ ```
26
+
27
+ ## Quick start
28
+
29
+ ```shell
30
+ # Search for models
31
+ hf2ollama search "qwen 7b gguf"
32
+
33
+ # See available quantizations and file sizes
34
+ hf2ollama list-files bartowski/Qwen2.5-Coder-7B-Instruct-GGUF
35
+
36
+ # Download and import into Ollama
37
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --quant Q4_K_M
38
+
39
+ # Fix Python SSL certificate issues if downloads fail
40
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --ssl-fix
41
+
42
+ # Use alternative download method (Windows, PowerShell 7 required)
43
+ hf2ollama pull bartowski/Qwen2.5-Coder-7B-Instruct-GGUF --alt-download
44
+ ```
45
+
46
+ ## Commands
47
+
48
+ ### pull
49
+
50
+ Download a GGUF model from HuggingFace and import into Ollama.
51
+
52
+ ```shell
53
+ hf2ollama pull <repo> [--quant Q4_K_M] [--name my-model] [--keep-gguf] [--ssl-fix] [--alt-download]
54
+ ```
55
+
56
+ Options:
57
+
58
+ - `--quant` / `-q` - Quantization level (Q2_K, Q3_K_M, Q4_K_M, Q5_K_M, Q6_K, Q8_0). Default: Q4_K_M.
59
+ - `--name` / `-n` - Ollama model name. Auto-generated from filename if not specified.
60
+ - `--keep-gguf` - Keep the GGUF file after importing into Ollama.
61
+ - `--ssl-fix` - Use OS certificate store instead of Python's default CA bundle.
62
+ - `--alt-download` - Use alternative PowerShell-based download method (Windows only, requires PowerShell 7).
63
+
64
+ The tool auto-detects the model family from the filename and generates the correct Modelfile with chat template and stop tokens.
65
+
66
+ ### search
67
+
68
+ Search HuggingFace for GGUF model repositories.
69
+
70
+ ```shell
71
+ hf2ollama search "llama 70b" --limit 20 --sort downloads
72
+ ```
73
+
74
+ ### list-files
75
+
76
+ Show available GGUF files in a repository with their sizes.
77
+
78
+ ```shell
79
+ hf2ollama list-files bartowski/Qwen2.5-Coder-7B-Instruct-GGUF
80
+ ```
81
+
82
+ ### list
83
+
84
+ List locally installed Ollama models.
85
+
86
+ ```shell
87
+ hf2ollama list
88
+ ```
89
+
90
+ ### remove
91
+
92
+ Delete an Ollama model.
93
+
94
+ ```shell
95
+ hf2ollama remove my-model:q4_k_m
96
+ ```
97
+
98
+ ### info
99
+
100
+ Show details about an installed Ollama model.
101
+
102
+ ```shell
103
+ hf2ollama info my-model:q4_k_m
104
+ ```
105
+
106
+ ### recommend
107
+
108
+ Recommend quantization based on your GPU VRAM and model size.
109
+
110
+ ```shell
111
+ # Auto-detect GPU VRAM
112
+ hf2ollama recommend --params 7
113
+
114
+ # Specify VRAM manually
115
+ hf2ollama recommend --params 70 --vram 24
116
+ ```
117
+
118
+ ### network-check
119
+
120
+ Check whether HuggingFace is reachable and whether SSL certificates are configured correctly.
121
+
122
+ ```shell
123
+ hf2ollama network-check
124
+ ```
125
+
126
+ ## Supported model families
127
+
128
+ The tool auto-detects model families from GGUF filenames and generates the correct Ollama Modelfile:
129
+
130
+ - Llama 3 / 3.1 / 3.2 / 3.3 / 4
131
+ - Gemma (2, 3, 4)
132
+ - Qwen (2, 2.5, 3)
133
+ - Mistral / Mixtral
134
+ - Phi (3, 4)
135
+ - DeepSeek (R1, V3)
136
+ - Granite
137
+ - Command-R
138
+ - ChatML (fallback for unrecognized models)
139
+
140
+ ## Supported quantizations
141
+
142
+ Q2_K, Q3_K_M, Q4_K_M (default), Q5_K_M, Q6_K, Q8_0
143
+
144
+ ## Configuration
145
+
146
+ Persistent config is stored in `~/.hf2ollama/config.toml`:
147
+
148
+ ```toml
149
+ download_dir = "C:/Users/you/.hf2ollama/downloads"
150
+ default_quant = "Q4_K_M"
151
+ hf_token = "hf_xxxxx"
152
+ ```
153
+
154
+ ## Requirements
155
+
156
+ - Python 3.10+
157
+ - Ollama installed locally
158
+ - For `--alt-download`: Windows + PowerShell 7
159
+
160
+ ## Dependencies
161
+
162
+ - click - CLI framework
163
+ - httpx - HTTP client with resumable downloads
164
+ - rich - Terminal tables and progress bars
165
+ - truststore - OS certificate store access
166
+ - certifi - Public CA bundle
167
+
168
+ ## License
169
+
170
+ MIT
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "hf2ollama-python-cli-tool"
3
+ version = "1.0.0"
4
+ description = "Search, download, and import HuggingFace GGUF models into Ollama"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.10"
8
+ authors = [
9
+ { name = "Tanmoy Dutta" },
10
+ ]
11
+ keywords = ["ollama", "huggingface", "gguf", "llm", "model-management"]
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "Intended Audience :: Developers",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ ]
23
+ dependencies = [
24
+ "click>=8.0",
25
+ "httpx>=0.27",
26
+ "rich>=13.0",
27
+ "truststore>=0.9",
28
+ "certifi",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=7.0",
34
+ "respx>=0.21",
35
+ "ruff>=0.4",
36
+ ]
37
+
38
+ [project.scripts]
39
+ hf2ollama = "hf2ollama.cli:main"
40
+
41
+ [project.urls]
42
+ Repository = "https://github.com/rs2pydev/hf2ollama-python-cli-tool"
43
+
44
+ [build-system]
45
+ requires = ["hatchling"]
46
+ build-backend = "hatchling.build"
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["src/hf2ollama"]
50
+
51
+ [tool.hatch.build.targets.wheel.shared-data]
52
+ "src/hf2ollama/scripts" = "hf2ollama/scripts"
53
+
54
+ [tool.ruff]
55
+ target-version = "py310"
56
+ line-length = 100
57
+
58
+ [tool.pytest.ini_options]
59
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """hf2ollama - Search, download, and import HuggingFace GGUF models into Ollama."""
2
+
3
+ __version__ = "1.0.0"