pxwebpy


Namepxwebpy JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummaryGet data from PxWeb API easily.
upload_time2024-02-11 14:32:45
maintainer
docs_urlNone
author
requires_python>=3.11
license
keywords dataframes pandas polars pxweb statistics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pxwebpy
[![ci](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml/badge.svg)](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)
![PyPI - Version](https://img.shields.io/pypi/v/pxwebpy)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pxwebpy)
[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json)](https://rye-up.com)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)   
Easily get data from the PxWeb API and into either a polars or pandas dataframe.  
  
Pxwebpy parses the PxWeb table data as well as metadata using the json-stat2 response format. 
  
It has been tested with [Statistics Sweden](https://scb.se), [Statistics Finland](https://www.stat.fi), [Statistics Greenland](https://stat.gl) and [Statistics Norway](https://www.ssb.no).  

## Example usage
```python
>>> from pxwebpy import PxWeb
>>> import pandas as pd

>>> URL = "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/HE/HE0110/HE0110A/SamForvInk1"

>>> QUERY = {
            "query": [
                {
                "code": "Tid",
                "selection": {
                    "filter": "item",
                    "values": [
                    "2021"
                    ]
                }
                }
            ],
            "response": {
                "format": "json-stat2"
            }
        }

>>> tbl = PxWeb(URL, QUERY)
>>> print(tbl)

PxWeb(url='https://api.scb.se/OV0104/v1/doris/sv/ssd/START/HE/HE0110/HE0110A/SamForvInk1',
    query={'query': [{'code': 'Tid', 'selection': {'filter': 'item', 'values': ['2021']}}], 'response': {'format': 'json-stat2'}},
    metadata={'label': 'Sammanräknad förvärvsinkomst för boende i Sverige hela året efter ålder, tabellinnehåll och år', 'source': 'SCB', 'updated': '2023-01-10T10:42:00Z'},
    last_refresh=2023-10-29 14:21:57.628639,
    dataset=[{'ålder': 'totalt 16+ år', 'tabellinnehåll': 'Medelinkomst, tkr', 'år': '2021' ...

>>> df = pd.DataFrame(tbl.dataset)
>>> print(df)
            ålder      tabellinnehåll    år      value
0   totalt 16+ år   Medelinkomst, tkr  2021      331.5
1   totalt 16+ år  Medianinkomst, tkr  2021      301.5
2   totalt 16+ år    Totalsumma, mnkr  2021  2779588.9
3   totalt 16+ år      Antal personer  2021  8383640.0
4        16-19 år   Medelinkomst, tkr  2021       28.1
..            ...                 ...   ...        ...
71       80-84 år      Antal personer  2021   290684.0
72         85+ år   Medelinkomst, tkr  2021      214.4
73         85+ år  Medianinkomst, tkr  2021      200.1
74         85+ år    Totalsumma, mnkr  2021    57529.3
75         85+ år      Antal personer  2021   268320.0

[76 rows x 4 columns]
```

See [examples](examples/example.py) for more details on how to use pxwebpy.
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pxwebpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "dataframes,pandas,polars,pxweb,statistics",
    "author": "",
    "author_email": "stefur <stefan@furne.net>",
    "download_url": "https://files.pythonhosted.org/packages/d1/d2/7edf1c1db356bd773d4abbd6f9e7e1725a87b8973e306ca1fc037c319d55/pxwebpy-0.2.0.tar.gz",
    "platform": null,
    "description": "# pxwebpy\n[![ci](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml/badge.svg)](https://github.com/stefur/pxwebpy/actions/workflows/ci.yml)\n![PyPI - Version](https://img.shields.io/pypi/v/pxwebpy)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pxwebpy)\n[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/mitsuhiko/rye/main/artwork/badge.json)](https://rye-up.com)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)   \nEasily get data from the PxWeb API and into either a polars or pandas dataframe.  \n  \nPxwebpy parses the PxWeb table data as well as metadata using the json-stat2 response format. \n  \nIt has been tested with [Statistics Sweden](https://scb.se), [Statistics Finland](https://www.stat.fi), [Statistics Greenland](https://stat.gl) and [Statistics Norway](https://www.ssb.no).  \n\n## Example usage\n```python\n>>> from pxwebpy import PxWeb\n>>> import pandas as pd\n\n>>> URL = \"https://api.scb.se/OV0104/v1/doris/sv/ssd/START/HE/HE0110/HE0110A/SamForvInk1\"\n\n>>> QUERY = {\n            \"query\": [\n                {\n                \"code\": \"Tid\",\n                \"selection\": {\n                    \"filter\": \"item\",\n                    \"values\": [\n                    \"2021\"\n                    ]\n                }\n                }\n            ],\n            \"response\": {\n                \"format\": \"json-stat2\"\n            }\n        }\n\n>>> tbl = PxWeb(URL, QUERY)\n>>> print(tbl)\n\nPxWeb(url='https://api.scb.se/OV0104/v1/doris/sv/ssd/START/HE/HE0110/HE0110A/SamForvInk1',\n    query={'query': [{'code': 'Tid', 'selection': {'filter': 'item', 'values': ['2021']}}], 'response': {'format': 'json-stat2'}},\n    metadata={'label': 'Sammanr\u00e4knad f\u00f6rv\u00e4rvsinkomst f\u00f6r boende i Sverige hela \u00e5ret efter \u00e5lder, tabellinneh\u00e5ll och \u00e5r', 'source': 'SCB', 'updated': '2023-01-10T10:42:00Z'},\n    last_refresh=2023-10-29 14:21:57.628639,\n    dataset=[{'\u00e5lder': 'totalt 16+ \u00e5r', 'tabellinneh\u00e5ll': 'Medelinkomst, tkr', '\u00e5r': '2021' ...\n\n>>> df = pd.DataFrame(tbl.dataset)\n>>> print(df)\n            \u00e5lder      tabellinneh\u00e5ll    \u00e5r      value\n0   totalt 16+ \u00e5r   Medelinkomst, tkr  2021      331.5\n1   totalt 16+ \u00e5r  Medianinkomst, tkr  2021      301.5\n2   totalt 16+ \u00e5r    Totalsumma, mnkr  2021  2779588.9\n3   totalt 16+ \u00e5r      Antal personer  2021  8383640.0\n4        16-19 \u00e5r   Medelinkomst, tkr  2021       28.1\n..            ...                 ...   ...        ...\n71       80-84 \u00e5r      Antal personer  2021   290684.0\n72         85+ \u00e5r   Medelinkomst, tkr  2021      214.4\n73         85+ \u00e5r  Medianinkomst, tkr  2021      200.1\n74         85+ \u00e5r    Totalsumma, mnkr  2021    57529.3\n75         85+ \u00e5r      Antal personer  2021   268320.0\n\n[76 rows x 4 columns]\n```\n\nSee [examples](examples/example.py) for more details on how to use pxwebpy.",
    "bugtrack_url": null,
    "license": "",
    "summary": "Get data from PxWeb API easily.",
    "version": "0.2.0",
    "project_urls": {
        "Issue tracker": "https://github.com/stefur/pxwebpy/issues"
    },
    "split_keywords": [
        "dataframes",
        "pandas",
        "polars",
        "pxweb",
        "statistics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83d7485e86edca46a2609afdefd0f111d93ad9e9bdd6ab1e731915757c0471df",
                "md5": "de90cf4b373c1fa24330a094079baa8f",
                "sha256": "4ac3610b4798ce68a8a3adaaba02ec2b2453448134e30c0e8267d11cfdc4f1aa"
            },
            "downloads": -1,
            "filename": "pxwebpy-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "de90cf4b373c1fa24330a094079baa8f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 5770,
            "upload_time": "2024-02-11T14:32:43",
            "upload_time_iso_8601": "2024-02-11T14:32:43.532457Z",
            "url": "https://files.pythonhosted.org/packages/83/d7/485e86edca46a2609afdefd0f111d93ad9e9bdd6ab1e731915757c0471df/pxwebpy-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1d27edf1c1db356bd773d4abbd6f9e7e1725a87b8973e306ca1fc037c319d55",
                "md5": "1852c14506f1e540fae7147def6f4478",
                "sha256": "beb104fa92442ea8c2805799fbf9fcecce22cdc2992e571d1083e4f04d4c9c17"
            },
            "downloads": -1,
            "filename": "pxwebpy-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1852c14506f1e540fae7147def6f4478",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 16110,
            "upload_time": "2024-02-11T14:32:45",
            "upload_time_iso_8601": "2024-02-11T14:32:45.050926Z",
            "url": "https://files.pythonhosted.org/packages/d1/d2/7edf1c1db356bd773d4abbd6f9e7e1725a87b8973e306ca1fc037c319d55/pxwebpy-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 14:32:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stefur",
    "github_project": "pxwebpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pxwebpy"
}
        
Elapsed time: 0.17825s