pycensus.census.countries.germany.api¶
API client for Destatis GENESIS-Online (Germany census/population data).
Technical aspects
See :mod:pycensus.germany.destatis.README for the full verification
log. In short: GENESIS-Online is a real RESTful/JSON API (base
https://genesis.destatis.de/genesisWS/rest/2020 -- note: no
"www-" prefix; the old www-genesis.destatis.de host 307-redirects
here), and a registered account (username/password, or a personal API
token used in place of username with password omitted, per GENESIS'
"Anwenderdokumentation Webservice/API" v5.1) is required to
authenticate. api_keys.json's "destatis_genesis" entry is a
single token string, resolved here as (token, "") by
:func:resolve_genesis_credentials.
Verified live 2026-08-21: the token currently configured in
api_keys.json DOES authenticate and DOES retrieve real data, once
two things are fixed relative to the 2026-08-20 attempt: (1) the
current host (above, no "www-" prefix -- the old host's REST path had
started 307/302-redirecting to a generic "announcement" page, which is
what made this look like a dead endpoint rather than a URL staleness
issue), and (2) per GENESIS' real spec ("Zugangsdaten: Felder im
HTTP-Header"), username/password must be sent as literal HTTP
request headers, not as fields in the POST body -- the 2026-08-20
attempt only tried body fields, HTTP Basic Auth, and a bearer header,
never a plain username/password header pair, which is the one
shape GENESIS actually documents and accepts. A real
helloworld/logincheck call with the configured token as the
username header (no password) returned
{"Status":"Sie wurden erfolgreich an- und abgemeldet! ...",
"Username":"<token>"} -- a real successful login, not the GAST
guest-account rejection.
GenesisCredentialsError
¶
Bases: RuntimeError
Raised when no GENESIS-Online credentials (token or username/password) are configured.
resolve_genesis_credentials(api_key=None, username=None, password=None)
¶
Resolve GENESIS-Online credentials.
Resolution order
- Explicit
username/passwordargs, if either is given. - A personal API token, resolved via :func:
pycensus.api_keys.resolve_api_keywith key name :data:pycensus.germany.constants.GENESIS_TOKEN_KEY(api_keys.json's"destatis_genesis"entry) or the :data:pycensus.germany.constants.GENESIS_TOKEN_ENVenv var, orapi_keyif passed explicitly -- used as(token, "")per GENESIS' token-in-place-of-username convention. - A real separate username/password pair, if configured under
:data:
pycensus.germany.constants.GENESIS_USERNAME_KEY/ :data:pycensus.germany.constants.GENESIS_PASSWORD_KEY.
Returns:
| Type | Description |
|---|---|
Tuple[str, str]
|
|
Raises:
| Type | Description |
|---|---|
GenesisCredentialsError
|
If none of the above resolve. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Explicit GENESIS token. |
None
|
username
|
Optional[str]
|
Explicit user name. |
None
|
password
|
Optional[str]
|
Explicit password. |
None
|
fetch_table(table_code, area=None, startyear=None, endyear=None, regionalvariable=None, regionalkey=None, api_key=None)
¶
Fetch one real GENESIS table (semicolon-delimited flat text) by table code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_code
|
str
|
GENESIS table code, e.g. |
required |
area
|
Optional[str]
|
GENESIS |
None
|
startyear
|
Optional[int]
|
First |
None
|
endyear
|
Optional[int]
|
Last |
None
|
regionalvariable
|
Optional[str]
|
The table's regional dimension code (e.g.
|
None
|
regionalkey
|
Optional[str]
|
A region code (or |
None
|
Raises:
| Type | Description |
|---|---|
GenesisCredentialsError
|
If no credentials are configured. |
list_datasets(year=2022)
¶
List the Destatis datasets pyCensus knows about (metadata only, no network call).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Reference year. |
2022
|
Returns:
| Type | Description |
|---|---|
List[dict]
|
Dataset descriptions. |