durable_huggingface_hub 0.2.0

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 (35) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +29 -0
  3. data/.rubocop.yml +108 -0
  4. data/CHANGELOG.md +127 -0
  5. data/README.md +547 -0
  6. data/Rakefile +106 -0
  7. data/devenv.lock +171 -0
  8. data/devenv.nix +15 -0
  9. data/devenv.yaml +8 -0
  10. data/huggingface_hub.gemspec +63 -0
  11. data/lib/durable_huggingface_hub/authentication.rb +245 -0
  12. data/lib/durable_huggingface_hub/cache.rb +508 -0
  13. data/lib/durable_huggingface_hub/configuration.rb +191 -0
  14. data/lib/durable_huggingface_hub/constants.rb +145 -0
  15. data/lib/durable_huggingface_hub/errors.rb +412 -0
  16. data/lib/durable_huggingface_hub/file_download.rb +831 -0
  17. data/lib/durable_huggingface_hub/hf_api.rb +1278 -0
  18. data/lib/durable_huggingface_hub/repo_card.rb +430 -0
  19. data/lib/durable_huggingface_hub/types/cache_info.rb +298 -0
  20. data/lib/durable_huggingface_hub/types/commit_info.rb +149 -0
  21. data/lib/durable_huggingface_hub/types/dataset_info.rb +158 -0
  22. data/lib/durable_huggingface_hub/types/model_info.rb +154 -0
  23. data/lib/durable_huggingface_hub/types/space_info.rb +158 -0
  24. data/lib/durable_huggingface_hub/types/user.rb +179 -0
  25. data/lib/durable_huggingface_hub/types.rb +205 -0
  26. data/lib/durable_huggingface_hub/utils/auth.rb +174 -0
  27. data/lib/durable_huggingface_hub/utils/headers.rb +220 -0
  28. data/lib/durable_huggingface_hub/utils/http.rb +329 -0
  29. data/lib/durable_huggingface_hub/utils/paths.rb +230 -0
  30. data/lib/durable_huggingface_hub/utils/progress.rb +217 -0
  31. data/lib/durable_huggingface_hub/utils/retry.rb +165 -0
  32. data/lib/durable_huggingface_hub/utils/validators.rb +236 -0
  33. data/lib/durable_huggingface_hub/version.rb +8 -0
  34. data/lib/huggingface_hub.rb +205 -0
  35. metadata +334 -0
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ # DurableHuggingfaceHub is a Ruby client library for the HuggingFace Hub.
4
+ #
5
+ # This library provides a pure Ruby implementation of the HuggingFace Hub client,
6
+ # enabling users to download models, datasets, and other files from the HuggingFace Hub,
7
+ # manage repositories, and interact with HuggingFace's inference APIs.
8
+ #
9
+ # @example Basic usage
10
+ # require "huggingface_hub"
11
+ #
12
+ # # Configure the library
13
+ # DurableHuggingfaceHub.configure do |config|
14
+ # config.token = "hf_your_token_here"
15
+ # end
16
+ #
17
+ # # Use the library features
18
+ # # (Additional features will be added in subsequent phases)
19
+ #
20
+ # @see https://huggingface.co HuggingFace Hub
21
+ # @see https://github.com/durableprogramming/huggingface-hub-ruby Project repository
22
+ module DurableHuggingfaceHub
23
+ # Autoload core modules for efficient memory usage
24
+ autoload :Constants, "durable_huggingface_hub/constants"
25
+ autoload :Configuration, "durable_huggingface_hub/configuration"
26
+ autoload :VERSION, "durable_huggingface_hub/version"
27
+ autoload :Types, "durable_huggingface_hub/types"
28
+ autoload :FileDownload, "durable_huggingface_hub/file_download"
29
+ autoload :HfApi, "durable_huggingface_hub/hf_api"
30
+ autoload :RepoCard, "durable_huggingface_hub/repo_card"
31
+ autoload :ModelCard, "durable_huggingface_hub/repo_card"
32
+ autoload :DatasetCard, "durable_huggingface_hub/repo_card"
33
+ autoload :SpaceCard, "durable_huggingface_hub/repo_card"
34
+ autoload :Cache, "durable_huggingface_hub/cache"
35
+
36
+ # Utils module with HTTP, retry, and header utilities
37
+ module Utils
38
+ autoload :Headers, "durable_huggingface_hub/utils/headers"
39
+ autoload :Retry, "durable_huggingface_hub/utils/retry"
40
+ autoload :HttpClient, "durable_huggingface_hub/utils/http"
41
+ autoload :Auth, "durable_huggingface_hub/utils/auth"
42
+ autoload :Validators, "durable_huggingface_hub/utils/validators"
43
+ autoload :Paths, "durable_huggingface_hub/utils/paths"
44
+ autoload :Progress, "durable_huggingface_hub/utils/progress"
45
+ end
46
+
47
+ # Load errors immediately since they may be needed for any operation
48
+ require_relative "durable_huggingface_hub/errors"
49
+
50
+ # Load authentication module
51
+ require_relative "durable_huggingface_hub/authentication"
52
+
53
+ class << self
54
+ # Returns the library version.
55
+ #
56
+ # @return [String] The current version string
57
+ def version
58
+ VERSION
59
+ end
60
+
61
+ # Returns the global configuration instance.
62
+ #
63
+ # @return [Configuration] The configuration instance
64
+ def configuration
65
+ Configuration.instance
66
+ end
67
+
68
+ # Configures the library with a block.
69
+ #
70
+ # @yield [config] The configuration instance
71
+ # @example
72
+ # DurableHuggingfaceHub.configure do |config|
73
+ # config.token = "hf_..."
74
+ # end
75
+ def configure
76
+ yield configuration if block_given?
77
+ end
78
+
79
+ # Delegates to Authentication.login
80
+ # @see Authentication.login
81
+ def login(token: nil, add_to_git_credential: false)
82
+ Authentication.login(token: token, add_to_git_credential: add_to_git_credential)
83
+ end
84
+
85
+ # Delegates to Authentication.logout
86
+ # @see Authentication.logout
87
+ def logout
88
+ Authentication.logout
89
+ end
90
+
91
+ # Delegates to Authentication.whoami
92
+ # @see Authentication.whoami
93
+ def whoami(token: nil)
94
+ Authentication.whoami(token: token)
95
+ end
96
+
97
+ # Delegates to Authentication.logged_in?
98
+ # @see Authentication.logged_in?
99
+ def logged_in?
100
+ Authentication.logged_in?
101
+ end
102
+
103
+ # Delegates to FileDownload.hf_hub_download
104
+ # @see FileDownload.hf_hub_download
105
+ def hf_hub_download(**kwargs)
106
+ FileDownload.hf_hub_download(**kwargs)
107
+ end
108
+
109
+ # Delegates to FileDownload.snapshot_download
110
+ # @see FileDownload.snapshot_download
111
+ def snapshot_download(**kwargs)
112
+ FileDownload.snapshot_download(**kwargs)
113
+ end
114
+
115
+ # Delegates to Cache.scan_cache_dir
116
+ # @see Cache.scan_cache_dir
117
+ def scan_cache_dir(**kwargs)
118
+ Cache.scan_cache_dir(**kwargs)
119
+ end
120
+
121
+ # Delegates to Cache.cached_assets_path
122
+ # @see Cache.cached_assets_path
123
+ def cached_assets_path(**kwargs)
124
+ Cache.cached_assets_path(**kwargs)
125
+ end
126
+
127
+ # Delegates to HfApi.repo_info
128
+ # @see HfApi.repo_info
129
+ def repo_info(repo_id, repo_type: "model", revision: nil, timeout: nil)
130
+ HfApi.new.repo_info(repo_id, repo_type: repo_type, revision: revision, timeout: timeout)
131
+ end
132
+
133
+ # Delegates to HfApi.model_info
134
+ # @see HfApi.model_info
135
+ def model_info(repo_id, revision: nil, timeout: nil)
136
+ HfApi.new.model_info(repo_id, revision: revision, timeout: timeout)
137
+ end
138
+
139
+ # Delegates to HfApi.dataset_info
140
+ # @see HfApi.dataset_info
141
+ def dataset_info(repo_id, revision: nil, timeout: nil)
142
+ HfApi.new.dataset_info(repo_id, revision: revision, timeout: timeout)
143
+ end
144
+
145
+ # Delegates to HfApi.space_info
146
+ # @see HfApi.space_info
147
+ def space_info(repo_id, revision: nil, timeout: nil)
148
+ HfApi.new.space_info(repo_id, revision: revision, timeout: timeout)
149
+ end
150
+
151
+ # Delegates to HfApi.list_models
152
+ # @see HfApi.list_models
153
+ def list_models(filter: nil, author: nil, search: nil, sort: nil,
154
+ direction: nil, limit: nil, full: false, timeout: nil)
155
+ HfApi.new.list_models(filter: filter, author: author, search: search, sort: sort,
156
+ direction: direction, limit: limit, full: full, timeout: timeout)
157
+ end
158
+
159
+ # Delegates to HfApi.list_datasets
160
+ # @see HfApi.list_datasets
161
+ def list_datasets(filter: nil, author: nil, search: nil, sort: nil,
162
+ direction: nil, limit: nil, full: false, timeout: nil)
163
+ HfApi.new.list_datasets(filter: filter, author: author, search: search, sort: sort,
164
+ direction: direction, limit: limit, full: full, timeout: timeout)
165
+ end
166
+
167
+ # Delegates to HfApi.list_spaces
168
+ # @see HfApi.list_spaces
169
+ def list_spaces(filter: nil, author: nil, search: nil, sort: nil,
170
+ direction: nil, limit: nil, full: false, timeout: nil)
171
+ HfApi.new.list_spaces(filter: filter, author: author, search: search, sort: sort,
172
+ direction: direction, limit: limit, full: full, timeout: timeout)
173
+ end
174
+
175
+ # Delegates to HfApi.repo_exists
176
+ # @see HfApi.repo_exists
177
+ def repo_exists(repo_id, repo_type: "model", timeout: nil)
178
+ HfApi.new.repo_exists(repo_id, repo_type: repo_type, timeout: timeout)
179
+ end
180
+
181
+ # Delegates to HfApi.whoami
182
+ # @see HfApi.whoami
183
+ # @raise [LocalTokenNotFoundError] If no token is provided or found
184
+ def whoami(token: nil)
185
+ # Ensure a token is available before making API call
186
+ token = Utils::Auth.get_token!(token: token)
187
+ HfApi.new(token: token).whoami
188
+ end
189
+
190
+ # Delegates to FileDownload.try_to_load_from_cache
191
+ # @see FileDownload.try_to_load_from_cache
192
+ def try_to_load_from_cache(**kwargs)
193
+ FileDownload.try_to_load_from_cache(**kwargs)
194
+ end
195
+
196
+ # Delegates to FileDownload.hf_hub_url
197
+ # @see FileDownload.hf_hub_url
198
+ def hf_hub_url(**kwargs)
199
+ FileDownload.hf_hub_url(**kwargs)
200
+ end
201
+ end
202
+ end
203
+
204
+ # Require version to make it available immediately
205
+ require_relative "durable_huggingface_hub/version"
metadata ADDED
@@ -0,0 +1,334 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: durable_huggingface_hub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - David Berube
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-multipart
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday-retry
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: dry-struct
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.6'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ - !ruby/object:Gem::Dependency
69
+ name: dry-types
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.7'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.7'
82
+ - !ruby/object:Gem::Dependency
83
+ name: ruby-progressbar
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.13'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.13'
96
+ - !ruby/object:Gem::Dependency
97
+ name: zeitwerk
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.6'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.6'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rake
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '13.0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '13.0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: minitest
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '5.0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '5.0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: minitest-reporters
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.6'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '1.6'
166
+ - !ruby/object:Gem::Dependency
167
+ name: webmock
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.18'
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '3.18'
180
+ - !ruby/object:Gem::Dependency
181
+ name: vcr
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '6.1'
187
+ type: :development
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '6.1'
194
+ - !ruby/object:Gem::Dependency
195
+ name: rubocop
196
+ requirement: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '1.50'
201
+ type: :development
202
+ prerelease: false
203
+ version_requirements: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '1.50'
208
+ - !ruby/object:Gem::Dependency
209
+ name: rubocop-minitest
210
+ requirement: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '0.31'
215
+ type: :development
216
+ prerelease: false
217
+ version_requirements: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '0.31'
222
+ - !ruby/object:Gem::Dependency
223
+ name: rubocop-rake
224
+ requirement: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '0.6'
229
+ type: :development
230
+ prerelease: false
231
+ version_requirements: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: '0.6'
236
+ - !ruby/object:Gem::Dependency
237
+ name: yard
238
+ requirement: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: '0.9'
243
+ type: :development
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '0.9'
250
+ - !ruby/object:Gem::Dependency
251
+ name: simplecov
252
+ requirement: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: '0.22'
257
+ type: :development
258
+ prerelease: false
259
+ version_requirements: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '0.22'
264
+ description: |
265
+ A complete, production-ready Ruby implementation of the HuggingFace Hub client library.
266
+ Download models, datasets, and manage repositories with zero Python dependencies.
267
+ Features smart caching, authentication, progress tracking, and comprehensive error handling.
268
+ email:
269
+ - commercial@durableprogramming.com
270
+ executables: []
271
+ extensions: []
272
+ extra_rdoc_files: []
273
+ files:
274
+ - ".editorconfig"
275
+ - ".rubocop.yml"
276
+ - CHANGELOG.md
277
+ - README.md
278
+ - Rakefile
279
+ - devenv.lock
280
+ - devenv.nix
281
+ - devenv.yaml
282
+ - huggingface_hub.gemspec
283
+ - lib/durable_huggingface_hub/authentication.rb
284
+ - lib/durable_huggingface_hub/cache.rb
285
+ - lib/durable_huggingface_hub/configuration.rb
286
+ - lib/durable_huggingface_hub/constants.rb
287
+ - lib/durable_huggingface_hub/errors.rb
288
+ - lib/durable_huggingface_hub/file_download.rb
289
+ - lib/durable_huggingface_hub/hf_api.rb
290
+ - lib/durable_huggingface_hub/repo_card.rb
291
+ - lib/durable_huggingface_hub/types.rb
292
+ - lib/durable_huggingface_hub/types/cache_info.rb
293
+ - lib/durable_huggingface_hub/types/commit_info.rb
294
+ - lib/durable_huggingface_hub/types/dataset_info.rb
295
+ - lib/durable_huggingface_hub/types/model_info.rb
296
+ - lib/durable_huggingface_hub/types/space_info.rb
297
+ - lib/durable_huggingface_hub/types/user.rb
298
+ - lib/durable_huggingface_hub/utils/auth.rb
299
+ - lib/durable_huggingface_hub/utils/headers.rb
300
+ - lib/durable_huggingface_hub/utils/http.rb
301
+ - lib/durable_huggingface_hub/utils/paths.rb
302
+ - lib/durable_huggingface_hub/utils/progress.rb
303
+ - lib/durable_huggingface_hub/utils/retry.rb
304
+ - lib/durable_huggingface_hub/utils/validators.rb
305
+ - lib/durable_huggingface_hub/version.rb
306
+ - lib/huggingface_hub.rb
307
+ homepage: https://github.com/durableprogramming/huggingface-hub-ruby
308
+ licenses:
309
+ - MIT
310
+ metadata:
311
+ allowed_push_host: https://rubygems.org
312
+ homepage_uri: https://github.com/durableprogramming/huggingface-hub-ruby
313
+ source_code_uri: https://github.com/durableprogramming/huggingface-hub-ruby
314
+ changelog_uri: https://github.com/durableprogramming/huggingface-hub-ruby/blob/master/CHANGELOG.md
315
+ documentation_uri: https://rubydoc.info/gems/huggingface_hub
316
+ bug_tracker_uri: https://github.com/durableprogramming/huggingface-hub-ruby/issues
317
+ rdoc_options: []
318
+ require_paths:
319
+ - lib
320
+ required_ruby_version: !ruby/object:Gem::Requirement
321
+ requirements:
322
+ - - ">="
323
+ - !ruby/object:Gem::Version
324
+ version: 3.0.0
325
+ required_rubygems_version: !ruby/object:Gem::Requirement
326
+ requirements:
327
+ - - ">="
328
+ - !ruby/object:Gem::Version
329
+ version: '0'
330
+ requirements: []
331
+ rubygems_version: 3.6.9
332
+ specification_version: 4
333
+ summary: Pure Ruby client for HuggingFace Hub
334
+ test_files: []