Add Geo Lookup Support
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với WIT binding tại stubs/wit_world/imports/geo.py và so sánh Python API được yêu cầu với các tham chiếu Rust, Go và JS trong issue. Sử dụng cấu hình định vị test.toml của Viceroy và các test @on_viceroy để kiểm thử các địa chỉ loopback và các địa chỉ đã cấu hình. Được xem là hoàn tất khi lookup API, biểu diễn response có kiểu, hành vi khi thất bại và độ bao phủ của Viceroy khớp với thiết kế đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Overview
Add support for Fastly's geographic and network intelligence API, which provides location and network information based on IP addresses.
WIT Interface
interface geo {
use types.{error, ip-address};
/// Returns JSON-encoded geographic data for an IP address
lookup: func(ip-addr: ip-address, max-len: u64) -> result<string, error>;
}
WIT bindings: stubs/wit_world/imports/geo.py
API Design
- Parse JSON response from WIT layer into a
Geodataclass with typed fields (city, country, coordinates, AS number, etc.) - Provide
lookup(ip)function acceptingstr,IPv4Address, orIPv6Address - Return
Nonefor failed lookups (e.g., private IPs without configuration) - Optional: convenience
lookup_client(request)helper
Cross-SDK Comparison:
-
Rust (
fastly::geo::geo_lookup): Returns strongly-typedGeostruct with enums forConnSpeed,ConnType,Continent,ProxyDescription,ProxyType. UsesOption<UtcOffset>fromtimecrate. All string/enum fields haveOther(String)variant for forward-compatibility. ReturnsOption<Geo>for missing data. -
Go (
geo.Lookup): Returns*Geostruct with all string fields (no enums). Returns pointer to empty struct when no data available. Uses rawintforUTCOffset(HHMM format like 200 or -500). -
JS (
getGeolocationForIpAddress): ReturnsGeolocationinterface with all fields asT | null. Uses strings for enums. Has bothutc_offset(number) andgmt_offset(string). Returnsnullfor no data.
Recommended Python approach:
- Use
@dataclasswith typed fields for known attributes - Include
_extra: dictfield (withrepr=False) to capture unknown JSON fields - Python
Enumtypes for categorical fields (e.g.,ConnType,Continent) using_missing_()to gracefully handle unknown values that might be added in future - Use
Optional[X](equivalent) for truly optional fields (region, utc_offset) - Return
Geo | Nonefromlookup()(align with Rust) - Consider
utc_offsetasOptional[datetime.timedelta]for Pythonic time handling - Match functionality from other SDKs for empty string values.
Forward Compatibility Pattern:
from dataclasses import dataclass, field
@dataclass
class Geo:
city: str
country_code: str
latitude: float
longitude: float
# ... other known fields
_extra: dict = field(default_factory=dict, repr=False)
@classmethod
def from_json(cls, data: dict):
known_fields = {'city', 'country_code', 'latitude', 'longitude', ...}
known = {k: v for k, v in data.items() if k in known_fields}
extra = {k: v for k, v in data.items() if k not in known_fields}
return cls(**known, _extra=extra)
def __getattr__(self, name):
if name in self._extra:
return self._extra[name]
raise AttributeError(f"no attribute '{name}'")
# Benefits: Type hints for known fields, future fields accessible via attributes
geo = Geo.from_json(json_data)
print(geo.city) # Type-checked by IDE
print(geo.timezone) # Works if Fastly adds this field later
Viceroy Testing
Viceroy supports geo lookups with configurable test data via test.toml:
[local_server.geolocation]
format = "inline-toml"
use_default_loopback = true # Returns default data for 127.0.0.1
[local_server.geolocation.addresses."203.0.113.42"]
city = "San Francisco"
country_code = "US"
latitude = 37.77869
# ... additional fields
Default loopback data is available without configuration. Tests can use @on_viceroy with inline TOML config or JSON file references.
Reference
- Ngôn ngữ chính
- Python
- Star
- 5
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fastly/compute-sdk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
fastly/compute-sdk-python#116 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
fastly/compute-sdk-python#98 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
fastly/compute-sdk-python#74 ·
-
Add HTTP Downstream Metadata API Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
fastly/compute-sdk-python#61 ·
-
fastly/compute-sdk-python#60 · 1 người được giao ·
Tất cả issue của fastly/compute-sdk-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
huggingface/Repo2RLEnv#163 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
NousResearch/hermes-agent#121143 ·