Skip to content

Add Area-based Pool logic for regional URL cycling#2

Merged
fern-support merged 4 commits into
mainfrom
devin/1767822715-area-based-pool
Jan 7, 2026
Merged

Add Area-based Pool logic for regional URL cycling#2
fern-support merged 4 commits into
mainfrom
devin/1767822715-area-based-pool

Conversation

@fern-support

@fern-support fern-support commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements Area-based Pool logic for regional URL cycling in the Python SDK, mirroring the implementation from the Go SDK PR.

Key additions:

  • Area enum (US, EU, AP, CN) representing global regions
  • Pool class for managing regional URLs with automatic cycling and DNS-based domain selection
  • Both sync (select_best_domain) and async (select_best_domain_async) DNS resolution
  • Support for both agora.io and sd-rtn.com domain suffixes
  • next_region() for cycling through region prefixes on failure
  • Agora and AsyncAgora clients now include domain pool integration

Updates since last revision

Refactored to extend base classes instead of duplicating code:

  • Agora now extends the base Agora class with domain pool support
  • AsyncAgora now extends the base AsyncAgora class with domain pool support
  • Only the pool-enabled clients are exported from the main package (original exports replaced)
  • Added edited files to .fernignore to prevent Fern from overwriting custom code

Usage: from agoraio import Agora, AsyncAgora, Area

Review & Testing Checklist for Human

  • Export change: The original Agora/AsyncAgora exports are replaced with pool-enabled versions. Verify this doesn't break existing consumers who don't want pool functionality (they must now provide area parameter)
  • Private attribute access: The clients directly modify _client_wrapper._base_url to update the base URL. Verify this internal access pattern is acceptable.
  • Thread safety in Pool class: The _domain_need_update() check happens outside the lock before acquiring it in select_best_domain(). Verify this double-checked locking pattern is acceptable.
  • Async lock usage: select_best_domain_async uses a synchronous threading.Lock inside an async method, which could block the event loop. Consider if this should use asyncio.Lock instead.

Test plan:

from agoraio import Agora, Area

client = Agora(
    area=Area.US,
    username="YOUR_USERNAME",
    password="YOUR_PASSWORD",
)
print(client.get_current_url())  # Should print https://api-us-west-1.agora.io
client.next_region()
print(client.get_current_url())  # Should print https://api-us-east-1.agora.io

# Verify inherited properties work
print(client.agents)  # Should return AgentsClient instance

Notes

  • No unit tests are included in this PR - tests should be added separately
  • This is part of a coordinated change across Go, TypeScript, and Python SDKs

Link to Devin run: https://app.devin.ai/sessions/ece6fb9b8ad84ec68720a1bcd7d64f93
Requested by: @fern-support

- Add Area enum (US, EU, AP, CN) for global regions
- Add Pool class for managing regional URLs with automatic cycling
- Add DNS-based resolver for selecting best available domain (sync and async)
- Add next_region() for cycling through region prefixes on failure
- Add select_best_domain() for DNS-based domain selection
- Support both agora.io and sd-rtn.com domain suffixes
- Export domain module from core and main package

Based on agora-rest-client-go/agora/domain implementation

Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 3 commits January 7, 2026 22:05
- Create AgoraPool that wraps Agora with domain pool
- Create AsyncAgoraPool that wraps AsyncAgora with domain pool
- Automatically use pool's current URL as base URL
- Expose pool, next_region(), select_best_domain(), get_current_url() methods
- Export AgoraPool and AsyncAgoraPool from main package

Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
- Agora and AsyncAgora now extend base classes instead of duplicating code
- Export only Agora/AsyncAgora (with pool support) from main package
- Add edited files to .fernignore to prevent Fern overwriting

Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
@fern-support fern-support merged commit afdf9d0 into main Jan 7, 2026
3 checks passed
@digitallysavvy digitallysavvy deleted the devin/1767822715-area-based-pool branch March 5, 2026 22:38
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.

2 participants