Skip to content

feat: add async support - #73

Merged
dunderrrrrr merged 5 commits into
dunderrrrrr:mainfrom
dojje:add-async-support
Jul 19, 2026
Merged

feat: add async support#73
dunderrrrrr merged 5 commits into
dunderrrrrr:mainfrom
dojje:add-async-support

Conversation

@dojje

@dojje dojje commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds AsyncBlocketAPI for async/await support. All search parameter logic is extracted into a shared _params.py module so the sync and async wrappers follow DRY — zero duplicated URL/param construction.

Architecture

_params.py          ← shared: build_search_params / build_car_params / build_boat_params / build_mc_params
    ↙         ↘
blocket.py    async_blocket.py   ← thin wrappers: only HTTP call differs
  • blocket_api/_params.py — pure functions that return (url, httpx_params) for every endpoint
  • blocket_api/blocket.py — refactored to delegate to _params.py (no more inline QueryParam logic)
  • blocket_api/async_blocket.py — new AsyncBlocketAPI class using httpx.AsyncClient, supports async with
  • tests/async_requests.py — 11 async tests mirroring the existing sync suite

Usage

from blocket_api import AsyncBlocketAPI

async with AsyncBlocketAPI() as api:
    results = await api.search("iPhone")
    cars = await api.search_car(models=[CarModel.VOLVO], locations=[Location.STOCKHOLM])

Verification

  • 22/22 tests pass (11 sync + 11 async)
  • mypy reports no type errors

@dojje

dojje commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

For context: this follows up on PR #11 from last year.

@dunderrrrrr dunderrrrrr changed the title feat: add AsyncBlocketAPI (DRY — shared param builder) feat: add async support Jul 19, 2026
@dunderrrrrr

Copy link
Copy Markdown
Owner

Thanks for your PR, this will be a great improvement.

I need to have a more thorrow look at this before merging but overall it looks good!

One thing though, could you maybe split the commits into multiple ones? I think the query param functions being moved to _params.py can be a separate commit. It'll be easier to review 🙂

Comment thread blocket_api/async_blocket.py Outdated
@dunderrrrrr dunderrrrrr self-assigned this Jul 19, 2026
@dunderrrrrr dunderrrrrr added the enhancement New feature or request label Jul 19, 2026
@dojje
dojje force-pushed the add-async-support branch from 10c4a86 to 0065d25 Compare July 19, 2026 09:04
@dojje

dojje commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Split into two commits as you suggested. Params function only returns params and not url. Constants for each function.

Comment thread tests/async_requests.py
@dunderrrrrr

Copy link
Copy Markdown
Owner

I have tested the code and it looks fine to me! There should not be any breaking changes here from what I can tell.

If you want to, feel free to add another commit updating the README, should be enough with just one example there I think. I can make the appropriate changes to the docs later 🙁

Thanks for your contribution! This will be a significant improvement 🚀

@dojje

dojje commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

I've changed the readme now

@dunderrrrrr
dunderrrrrr merged commit 877c60e into dunderrrrrr:main Jul 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants