Skip to main content

dapla-statbank-client

Used internally by SSB (Statistics Norway). Validates and transfers data from Dapla to Statbank. Gets data from public and internal statbank.

Usage Transferring

from statbank import StatbankClient
stat_client = StatbankClient(loaduser = "LASTEBRUKER")
# Fill out password
stat_client.transfer(df_06399, tabellid="06339")

The simplest form of usage, is directly-transferring using the transfer-method under the client-class. If the statbanktable expects multiple "deltabeller", dataframes must be passed in a list, in the correct order.

Validation will happen by default on user-side, in Python, using the "UttrekksBeskrivelse" (filbeskrivelse). Validation can be disabled using the "validation"-parameter on the client. Validation happens on the number of tables, number of columns, code usage in categorical columns, code usage in "suppression-columns" (prikkkolonner), and on timeformats (both length and characters used).

You can validate the data using the validate-method, without starting a transfer, like this:

stat_client.validate(df_06339, tableid="06339")

You can also look at the "filbeskrivelse" which is in its own local class: StatbankUttrekksBeskrivelse

description_06339 = stat_client.get_description(tableid="06339")
print(description_06339)

Usage get apidata

client.apidata_all("06339", include_id=True)

apidata_all, does not need a specified query, it will build its own query, trying to get all the data from the table. This might be too much, resulting in an error.

The include_id-parameter is a bit magical, it gets both codes and value-columns for categorical columns, and tries to merge these next to each other, it also makes a check if the content i the same, then it will not include the content twice.

If you want to specify a query, to limit the response, use the method apidata instead.
Here we are requesting an "internal table" which only people at SSB have access to, with a specified URL and query.

query = {'query': [{'code': 'Region', 'selection': {'filter': 'vs:Landet', 'values': ['0']}}, {'code': 'Alder', 'selection': {'filter': 'vs:AldGrupp19', 'values': ['000', '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014', '015', '016', '017', '018', '019', '020', '021', '022', '023', '024', '025', '026', '027', '028', '029', '030', '031', '032', '033', '034', '035', '036', '037', '038', '039', '040', '041', '042', '043', '044', '045', '046', '047', '048', '049', '050', '051', '052', '053', '054', '055', '056', '057', '058', '059', '060', '061', '062', '063', '064', '065', '066', '067', '068', '069', '070', '071', '072', '073', '074', '075', '076', '077', '078', '079', '080', '081', '082', '083', '084', '085', '086', '087', '088', '089', '090', '091', '092', '093', '094', '095', '096', '097', '098', '099', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119+']}}, {'code': 'Statsbrgskap', 'selection': {'filter': 'vs:Statsborgerskap', 'values': ['000']}}, {'code': 'Tid', 'selection': {'filter': 'item', 'values': ['2022']}}], 'response': {'format': 'json-stat2'}}

client.apidata("https://i.ssb.no/pxwebi/api/v0/no/prod_24v_intern/START/be/be01/folkemengde/Rd0002Aa",
        query,
        include_id = True
       )

Usage batches

For the transferring methods, there are "twin" batch-methods. Alternatively you can just run the methods above multiple times...

To transfer many tables at the same time.

transfers = stat_client.transfer_batch({"06339": df_06399,
                                        "05300": df_05300})
print(transfers["05300"])

To validate many tables at the same time.

stat_client.validate_batch({"06339": df_06399,
                            "05300": df_05300})

To get many descriptions at once send a list.

descriptions = stat_client.validate_batch(["06339","05300"])
print(descriptions["06339"])

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dapla_statbank_client-0.0.1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dapla_statbank_client-0.0.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file dapla_statbank_client-0.0.1.tar.gz.

File metadata

  • Download URL: dapla_statbank_client-0.0.1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for dapla_statbank_client-0.0.1.tar.gz
Algorithm Hash digest
SHA256 970f42e63af1421954a669d5a7ccf6d33fcac48d242f7d5d4fe254c9ec553af9
MD5 de842ec617666d93939f0e599e45a0d4
BLAKE2b-256 da6132e87dc4308a93b839df73357bca5f78e24f851f4de67a3c72b04022d931

See more details on using hashes here.

File details

Details for the file dapla_statbank_client-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dapla_statbank_client-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9fda1762a171b44f67056bbf7c94e8b783f14a5113939dfa480b0d2ab5a8d0fb
MD5 ed6e4e737432ab595240798efb5e59e7
BLAKE2b-256 f36ebdee25d66d98a11fb068af42942ba69de70d74b5a6982ed954906632a53c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page