콘텐츠로 이동

Environment variables — KPubData SDK

This page documents the current implemented names. It is for users of the standalone Python SDK. The names here are not a proposal to rename your existing settings: a separate post-MVP issue, #988, covers possible readability improvements and backward-compatible migration.

Provider API credentials

Set only keys for providers you actually use. Each provider or service can require its own registration or API-specific approval: a key that exists is not proof the dataset is authorized or verified.

Provider Current environment variable Credential source / note
datago KPUBDATA_DATAGO_API_KEY Public Data Portal; dataset-specific activation may be required
localdata, semas KPUBDATA_DATAGO_API_KEY (shared default) These adapters first honor their own KPUBDATA_LOCALDATA_API_KEY / KPUBDATA_SEMAS_API_KEY override, then fall back to the data.go.kr key
lofin KPUBDATA_LOFIN_API_KEY LOFIN365; independently issued credential, never a data.go.kr fallback
neis KPUBDATA_NEIS_API_KEY NEIS Open API; not a data.go.kr shared-key fallback
fds KPUBDATA_FDS_API_KEY Food Safety Korea Open API; not a data.go.kr shared-key fallback
bok KPUBDATA_BOK_API_KEY Bank of Korea ECOS
kosis KPUBDATA_KOSIS_API_KEY KOSIS
seoul KPUBDATA_SEOUL_API_KEY Seoul Open Data
sgis KPUBDATA_SGIS_API_KEY + KPUBDATA_SGIS_CONSUMER_SECRET The first value is SGIS's consumer key; both values are required for the default two-part token exchange. Without KPUBDATA_SGIS_CONSUMER_SECRET, a key written as key:secret is split at the first :; with it set, the key is used whole, colon included
law, kipris, korean KPUBDATA_LAW_API_KEY, KPUBDATA_KIPRIS_API_KEY, KPUBDATA_KOREAN_API_KEY Each provider's own credential issuer
krx None This optional backend does not require an SDK API key

LOFIN credential boundary: LOFIN365 issues its own API key; the SDK now requires its own lofin credential rather than sending an unrelated data.go.kr key to the LOFIN365 host. Previously configured users must set KPUBDATA_LOFIN_API_KEY before calling LOFIN. This is an intentional change in authentication behavior. Live provider verification remains separate.

Lookup order

For ordinary providers, the runtime checks these values in order:

  1. An explicit Client(provider_keys={"provider": "..."}) entry.
  2. KPUBDATA_<PROVIDER>_API_KEY.
  3. The legacy <PROVIDER>_API_KEY variable.

For localdata and semas, after their provider-specific lookup fails, the SDK falls back to datago using its own normal lookup order. An explicit provider-specific key wins over the shared key. This is the existing behavior, not a new cross-provider secret-sharing feature.

Client(provider_keys={...}, env_keys=False) disables all environment credential fallback, including the SGIS consumer secret. Use this mode for requests where the supplied key must never be replaced with a service operator's ambient credential. A local test relying on environment variables must not be mistaken for verification of another user's key.

Other SDK settings

Name Meaning Current value and default
KPUBDATA_CACHE Enable the response cache when using Client.from_env() Exactly 1 enables it; any other value, including true or yes, leaves it off (the default)
KPUBDATA_CACHE_DIR Local response-cache directory Optional; ignored unless KPUBDATA_CACHE=1
KPUBDATA_CACHE_TTL Cache lifetime in seconds Integer, default 86400 (24 hours); an empty value means the default, a non-integer raises ConfigError

These three are read only by Client.from_env(). A plain Client() ignores them, and an explicit cache or cache_ttl_seconds argument wins over them.

The API constructor has corresponding explicit arguments such as cache_ttl_seconds. The environment variable retains its current KPUBDATA_CACHE_TTL name for compatibility. See cache usage and CLI options.

The existing KPUBDATA_<PROVIDER>_EXTRA_HOSTS setting extends that provider's credential destination allowlist. Its value is a comma- or whitespace-separated list of exact hostnames (case-insensitive); it does not accept wildcard or suffix matches. Leave it unset unless a reviewed destination needs access to that provider's credentials. It does not permit sending credentials over HTTP. See host allowlists.

XDG_CACHE_HOME sets the root for the default cache directory: $XDG_CACHE_HOME/kpubdata/responses. Without it, the default is ~/.cache/kpubdata/responses. An explicit cache directory takes precedence.

Verification-only variables

  • KPUBDATA_DATAGO_REALESTATE_ENABLED=1 is an integration-test opt-in flag. Set it only after the particular real-estate service has approved the operator's API key. It does not grant permission.
  • KPUBDATA_MODE=replay is used by the recorded-response examples and verification tooling. The SDK reads it on every request: a request whose dataset and URL have a recording under KPUBDATA_REPLAY_DIR is answered from it (or fails with InvalidRequestError if no recording matches its parameters), and any other request still goes to the live API. It is not a switch that makes every Client call offline.
  • KPUBDATA_REPLAY_DIR overrides the recorded-response fixture root used by replay mode. Its value is a directory path; the default is tests/fixtures relative to the current working directory. This does not enable replay by itself.
  • KPUBDATA_KRX_INTEGRATION=1 opts in to the KRX integration tests; installing its optional backend does not establish live verification.
  • KPUBDATA_BASELINE_BASE identifies the Git ref used for baseline comparisons by make verify (its default is origin/main). LIVE=1 enables the verifier's explicit live stage; ordinary offline verification does not grant permission to send credentials or create trusted recordings.
  • Recorder-only KPUBDATA_RECORDER, KPUBDATA_RECORD_COMMIT and KPUBDATA_RECORD_RUN describe evidence provenance. They are not SDK credential settings, and setting them does not certify the recording's authorship.
  • CI secrets and GitHub Actions settings are operational controls, not extra required SDK user configuration. See live-provider verification for their distinct scope.

Safety: Never print credential values for a configuration check, include keys in screenshots or logs, or commit a real .env file. A successful fixture/replay run is not evidence that a real provider accepted the key. Current real-API test arrangements are tracked in #887.