A comprehensive Python wrapper for the Statistics Sweden PxWebAPI 2.0 (beta), providing easy access to Swedish statistical data.
- Complete Python interface for Statistics Sweden's PxWebAPI 2.0
- Intuitive navigation and exploration of the database structure
- Comprehensive search functionality for statistical tables
- Flexible data filtering and selection options
- Support for multiple data formats:
- Pandas DataFrames with customizable options
- JSON (json-stat2 format)
- CSV with various delimiter options
- Excel (XLSX)
- HTML
- Parquet
- Built-in API rate limit controls
- Built-in error handling and intelligent response parsing
- Multilanguage support (Swedish/English)
- Python 3.7 or higher
- Dependencies:
- pandas >= 1.0.0
- requests >= 2.25.0
Install the latest version from GitHub:
pip install git+https://github.com/xemarap/pxstatspy.git
For development installation:
git clone https://github.com/xemarap/pxstatspy.git
cd pxstatspy
pip install -e .
Visit the PxStatsPy - Get started tutorial notebook for extensive usage guide.
from pxstatspy import PxAPI, PxAPIConfig, OutputFormat, OutputFormatParam
# Initialize client
config = PxAPIConfig(
base_url="https://api.scb.se/ov0104/v2beta/api/v2",
language="en" # or "sv" for Swedish
)
client = PxAPI(config)
# Search for population statistics tables updated last 30 days
client.find_tables(
query="Population",
past_days=30,
display=True
)
# Get data as DataFrame
df = client.get_data_as_dataframe(
table_id="TAB1267",
value_codes={
"Tid": ["2024"],
"Region": ["00", "01"],
"ContentsCode": ["BE0101A9"]
}
)
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Submit suggestions and report bugs (for faster troubleshooting please enable debug mode and submit the errormessage)
- Open a Pull Request
- Star the GitHub page
This project is licensed under the MIT License - see the LICENSE file for details.
- Statistics Sweden for providing the PxWebAPI 2.0 (beta)
- Contributors to the project
This project uses the following open source packages:
The full license texts are available in the LICENSES directory.