Skip to content

feat: Improve rate limiter implementation#8

Merged
AN0DA merged 9 commits into
mainfrom
rate-limiter-refactor
Mar 28, 2026
Merged

feat: Improve rate limiter implementation#8
AN0DA merged 9 commits into
mainfrom
rate-limiter-refactor

Conversation

@AN0DA

@AN0DA AN0DA commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Summary

Rate limiting and HTTP response caching move from pybdl.api.utils into pybdl.utils, with BaseAPIClient calling dedicated HTTP client factories. BaseAccess column typing is tightened for object and string dtypes. The branch also bumps the version to 0.1.0, limits releases to workflow_dispatch, ignores .worktrees/, and updates uv.lock.

Purpose & Context

Keeping transport concerns (hishel-backed caching, quota persistence) under pybdl.utils clarifies layering: the API package stays oriented around BDL client behavior while public symbols remain available from pybdl.utils.rate_limiter. Factoring HTTP cache setup into pybdl.utils.http_cache isolates testable construction logic. The access-layer change reduces fragile coercion when columns are already typed or empty and aligns behavior with current pandas APIs.

Changes Made

  • Rate limiter: New package pybdl.utils.rate_limiter (_sync, _async, _cache, _decorators, shared base); removes pybdl.api.utils rate limiter and quota_cache modules. Docs and tests import from pybdl.utils.rate_limiter; package tests cover the exported API.
  • HTTP cache: New pybdl.utils.http_cache for cache DB path resolution, sync/async client builders, and cache-hit inspection; pybdl/api/client.py consumes these.
  • Access & repo: pybdl/access/base.py _convert_column_types and RST example fix; release workflow, .gitignore, version, lockfile.

Testing

uv run pytest tests/unit/utils/utils/test_http_cache.py tests/unit/utils/utils/rate_limiter/ tests/unit/api/test_api_client_cache.py — 75 passed. Full suite and Sphinx build were not run for this description.

Breaking Changes & Migration Notes

Anyone importing from pybdl.api.utils.rate_limiter (or the removed quota_cache module) must switch to pybdl.utils.rate_limiter (and use PersistentQuotaCache from there). Behavior of rate limiting and HTTP caching is intended to be equivalent; verify any code that relied on undocumented internal modules.

Review Focus Areas

  • HTTP cache path: resolve_http_cache_db_path ties the on-disk cache to the quota cache file location; confirm this still matches deployment and multi-process expectations.
  • Rate limiter: Internal split is structural; worth spot-checking sync/async interaction and persistent cache atomic paths if reviewers have context on prior race-condition fixes.
  • BaseAccess: Coercion logic changes affect all access subclasses; scrutiny on mixed-type columns and string dtypes is warranted.

Dependencies & Side Effects

uv.lock has a large refresh alongside the version bump; reviewers may want to skim dependency deltas if supply-chain or reproducibility policies apply.

AN0DA and others added 9 commits March 28, 2026 21:31
…ructure

- Migrate rate limiting utilities from `pybdl.api.utils` to `pybdl.utils.rate_limiter`
- Update import paths in documentation and client code to reflect new structure
- Remove deprecated files related to rate limiting
- Introduce a base class for shared logic between synchronous and asynchronous rate limiters
- Ensure backward compatibility with existing functionality while improving organization
…rkflow

- Simplified the release workflow by removing the push and pull_request triggers, retaining only the workflow_dispatch event.
- Adjusted the example formatting in the BaseAccess class to use a block-style example for clarity.
- Bump project version in pyproject.toml from 0.0.1 to 0.1.0.
- Include .worktrees directory in .gitignore to prevent tracking of worktree files.
- Streamlined the type conversion process for DataFrame columns in the BaseAccess class.
- Enhanced checks for object and string dtypes before attempting conversion to numeric or boolean types.
- Improved handling of non-null values to ensure accurate type casting.
- Refactored the numeric conversion checks for DataFrame columns to improve readability and efficiency.
- Consolidated conditional statements for dtype checks and non-null value handling.
- Ensured accurate type casting for integer-like values in the DataFrame.
… BaseAPIClient

- Added new module for HTTP caching utilities, including functions to build sync and async HTTP clients with caching support.
- Updated BaseAPIClient to utilize new caching functions, improving cache management and client initialization.
- Implemented helper functions to determine if responses are served from cache.
- Added tests for caching functionality to ensure correct behavior across different cache backends.
@github-actions

github-actions Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Test Results

553 tests   542 ✅  7s ⏱️
  1 suites   11 💤
  1 files      0 ❌

Results for commit 61475cf.

♻️ This comment has been updated with latest results.

@AN0DA AN0DA merged commit e78c55b into main Mar 28, 2026
11 checks passed
@AN0DA AN0DA deleted the rate-limiter-refactor branch March 28, 2026 20:51
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.

1 participant