Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add Geo Lookup Support

オープン
#48 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
api, backend

調査の方向性

stubs/wit_world/imports/geo.py の WIT バインディングから始め、要求された Python API を issue 内の Rust、Go、JS のリファレンスと比較します。Viceroy の test.toml ジオロケーション設定と @on_viceroy テストを使用して、ループバックアドレスと設定済みアドレスをテストします。lookup API、型付きレスポンス表現、失敗時の動作、Viceroy のカバレッジが記載された設計と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 Geo dataclass with typed fields (city, country, coordinates, AS number, etc.)
  • Provide lookup(ip) function accepting str, IPv4Address, or IPv6Address
  • Return None for failed lookups (e.g., private IPs without configuration)
  • Optional: convenience lookup_client(request) helper

Cross-SDK Comparison:

  • Rust (fastly::geo::geo_lookup): Returns strongly-typed Geo struct with enums for ConnSpeed, ConnType, Continent, ProxyDescription, ProxyType. Uses Option<UtcOffset> from time crate. All string/enum fields have Other(String) variant for forward-compatibility. Returns Option<Geo> for missing data.

  • Go (geo.Lookup): Returns *Geo struct with all string fields (no enums). Returns pointer to empty struct when no data available. Uses raw int for UTCOffset (HHMM format like 200 or -500).

  • JS (getGeolocationForIpAddress): Returns Geolocation interface with all fields as T | null. Uses strings for enums. Has both utc_offset (number) and gmt_offset (string). Returns null for no data.

Recommended Python approach:

  • Use @dataclass with typed fields for known attributes
  • Include _extra: dict field (with repr=False) to capture unknown JSON fields
  • Python Enum types 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 | None from lookup() (align with Rust)
  • Consider utc_offset as Optional[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

主要言語
Python
スター
5
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fastly/compute-sdk-python のほかの issue

fastly/compute-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。