Skip to content

Conversation

@geetu040
Copy link
Contributor

Towards #1575

This PR sets up the core folder and file structure along with base scaffolding for the API v1 → v2 migration.

It includes:

  • Skeleton for the HTTP client, backend, and API context
  • Abstract resource interfaces and versioned stubs (*V1, *V2)
  • Minimal wiring to allow future version switching and fallback support

No functional endpoints are migrated yet. This PR establishes a stable foundation for subsequent migration and refactor work.

@geetu040 geetu040 mentioned this pull request Dec 30, 2025
25 tasks
@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 0% with 207 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.37%. Comparing base (645ef01) to head (5762185).

Files with missing lines Patch % Lines
openml/_api/http/client.py 0.00% 69 Missing ⚠️
openml/_api/resources/tasks.py 0.00% 47 Missing ⚠️
openml/_api/config.py 0.00% 32 Missing ⚠️
openml/_api/runtime/core.py 0.00% 27 Missing ⚠️
openml/_api/resources/datasets.py 0.00% 9 Missing ⚠️
openml/_api/resources/base.py 0.00% 8 Missing ⚠️
openml/_api/runtime/fallback.py 0.00% 6 Missing ⚠️
openml/_api/__init__.py 0.00% 4 Missing ⚠️
openml/_api/resources/__init__.py 0.00% 3 Missing ⚠️
openml/_api/http/__init__.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1576      +/-   ##
==========================================
- Coverage   52.78%   50.37%   -2.41%     
==========================================
  Files          36       46      +10     
  Lines        4331     4538     +207     
==========================================
  Hits         2286     2286              
- Misses       2045     2252     +207     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

cache: CacheConfig


settings = Settings(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the settings to the individual classes. I think this design introduces too high coupling of the classes to this file. You cannot move the classes around, or add a new API version without making non-extensible changes to this file here - because APISettings will require a constructor change and new classes it accepts.

Instead, a better design is to apply the strategy pattern cleanly to the different API definitions - v1 and v2 - and move the config either to their __init__, or a set_config (or similar) method.

Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall really great, I have a design suggestion related to the configs.

The config.py file and the coupling on it breaks an otherwise nice strategy pattern.

I recommend to follow the strategy pattern cleanly instead, and move the configs into the class instances, see above.

This will make the backend API much more extensible and cohesive.

key="...",
),
v2=APIConfig(
server="http://127.0.0.1:8001/",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be hardcoded? I guess this is just for your local development

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard-coded, they are the default values though the local endpoints will be replaced by remote server when deployed hopefully before merging this in main


if strict:
return v2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous commit the 'FallbackProxy' was used here. Do we still need this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because of the ruff errors. I'll put them back and fix the pre-commit when the class is implemented.

if use_cache:
try:
return self._get_cache_response(cache_dir)
# TODO: handle ttl expired error
Copy link
Collaborator

@SimonBlanke SimonBlanke Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is out of draft, but this caching is not implemented. I guess this is out of scope for this PR.

Copy link
Contributor Author

@geetu040 geetu040 Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the PR is currently a draft, should I mark it with draft as well? There are a bunch of work items that I'll separate if they can worked without affecting derived PRs, otherwise implement myself. For caching specifically I plan to implement it myself otherwise stacking is going to be challenging.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general a draft marks a PR where changes are not finalized. I do it the following way: If a PR is not finished and needs developer input for implementation I open a draft. If I think the PR is finished and can be merged, then I change it to a normal PR. But I cannot find an explanation that matches my procedure, so I guess this is just my practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll put this as draft since that doesn't hurt it from getting reviewed or other people working on top of it.


return task

def _create_task_from_xml(self, xml: str) -> OpenMLTask:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method already exists here: https://github.com/openml/openml-python/pull/1576/files/74ab3662b6be04d001b1e8dade3f695ca80bcfad#diff-fdaf60448460bf4c7af496380c2f8967b0cabe577a9153256b8397f9f80e0eccR460

Is it really needed at both locations or can we remove one of them? That would be good to avoid duplicate code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right. this resource implementation was just to give out an example, it will be removed anyways and this duplication will be taken care of in the derived PR specifically for tasks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonBlanke the thread on discord discussing this, in case you want to weigh in.

Copy link
Collaborator

@PGijsbers PGijsbers Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thread is not accessible to me. (though I assume from context it's also not that important)

from openml._api.resources.base import DatasetsAPI

if TYPE_CHECKING:
from responses import Response
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In production this would be requests, right? You used responses for the mocking here during development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this should should be requests, I'll fix it.

@geetu040 geetu040 changed the title [ENH] Migration: set up core/base structure [ENH] V1 → V2 API Migration - core structure Jan 9, 2026
@geetu040 geetu040 marked this pull request as draft January 12, 2026 18:47
Copy link
Collaborator

@PGijsbers PGijsbers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I agree with the suggested changes. This seems like a reasonable way to provide a unified interface for two different backends, and also separate out some concerns that were previously coupled or scattered more than they should (e.g., caching, configurations).

My main concern is with the change to caching behavior. I have a minor concern over the indirection APIContext introduces (perhaps I misunderstood its purpose), and the introduction of allowing Response return values.

In my comments you will also find some things that may already have been "wrong" in the old implementation. In that case, I think it simply makes sense to make the change now so I repeat it here for convenience.

from openml._api.config import APIConfig


class CacheMixin:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ttl should probably heavily depend on the path. If we do end up using caching at this level, we should use the Cache-Control HTTP Header response so the server can inform us how long to keep it in cache for (something that, I believe, neither servers do right now). A dataset search query can change if any dataset description changes (to either be now included or excluded), so caching probably shouldn't even be on by default for such type of queries. Dataset descriptions might change, but likely not very frequently. Dataset data files or computed qualities should (almost?) never change. This is the reason that the current implementation only caches description, features, qualities, and the dataset itself.

With this implementation, you also introduce some new issues:

  • What if the paths change, or even the query parameters? there is now dead cache. Do we now add cache cleanup routines? How does openml-python know what is no longer valid if they were responses with high TTL?
  • URLs may be (much) longer than the default max path of Windows (260 characters). If I'm not mistaken, this will lead to an issue unless you specifically work around it.
  • More of an implementation detail, but authenticated and unauthenticated requests are not differentiated. If a user accidentally makes an unauthenticated request, gets an error, and then authenticates they would still get an error.


class DatasetsAPI(ResourceAPI, ABC):
@abstractmethod
def get(self, dataset_id: int) -> OpenMLDataset | tuple[OpenMLDataset, Response]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an API design perspective, I am not sure what the usecase for the user is to want access to the requests.Response. The only case I can think of is to parse the data itself but if the user wants to do that I reckon we failed in our API design? I will be the first to admit that error handling needs to be improved (both on the server and client side), but I don't think this makes sense. Am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment of course applies not just to the DatasetsAPI, but all of the resource apis

tasks=TasksV1(v1_http),
)

if version == "v1":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: supported versions should be encoded in an Enum. This helps function signatures (type checking, code completion) and reduces chance for erroneous input.

Comment on lines +1 to +8
from openml._api.runtime.core import APIContext


def set_api_version(version: str, *, strict: bool = False) -> None:
api_context.set_version(version=version, strict=strict)


api_context = APIContext()
Copy link
Collaborator

@PGijsbers PGijsbers Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what the function of the APIContext is here. Why do we need it and cannot just use backend directly? E.g.:

Suggested change
from openml._api.runtime.core import APIContext
def set_api_version(version: str, *, strict: bool = False) -> None:
api_context.set_version(version=version, strict=strict)
api_context = APIContext()
from openml._api.runtime.core import build_backend
_backend = build_backend("v1", strict=False)
def set_api_version(version: str, *, strict: bool = False) -> None:
global _backend
_backend = build_backend(version=version, strict=strict)
def backend() -> APIBackend:
return _backend

If it is just to avoid the pitfall where users assign the returned value to a local variable with a scope that is too long lived, then the same would apply if users would assign api_context.backend to a variable. We could instead extend the APIBackend class to allow updates to its attributes?

from dataclasses import dataclass
from typing import Literal

DelayMethod = Literal["human", "robot"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should be an enum.

server: str
base_url: str
key: str
timeout: int = 10 # seconds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add a unit suffix (timeout_seconds) so the unit is clear without navigating to the source.

ps. I also considered typing it as datetime.timedelta but considering you probably only use it in seconds and there is a real risk of developers erroneously using datetime.timedelta.seconds instead of datetime.timedelta.total_seconds(), I think keeping it an integer is better.

class ConnectionConfig:
retries: int = 3
delay_method: DelayMethod = "human"
delay_time: int = 1 # seconds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here too, including the unit makes sense (delay_time_seconds)

@dataclass
class CacheConfig:
dir: str = "~/.openml/cache"
ttl: int = 60 * 60 * 24 * 7 # one week
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Considering the TTL of the HTTP standard is already defined in seconds, maybe it is fine to exclude it in the variable name? Though as noted above there is a discussion to be had about having this as a cache level property in the first place.
For future reference, setting the value to timedelta(weeks=1).total_seconds() is preferred over the arithmetic+comment.


@dataclass
class CacheConfig:
dir: str = "~/.openml/cache"
Copy link
Collaborator

@PGijsbers PGijsbers Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default should continue to respect XDG_CACHE_HOME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants