A Python wrapper for the Statistics Sweden PxWebAPI 2.0
Project description
PxStatsPy
A comprehensive Python wrapper for the Statistics Sweden PxWebAPI 2.0, providing easy access to Swedish statistical data.
Note: This is an independent project and is not associated with Statistics Sweden (SCB).
Features
- Complete Python interface for Statistics Sweden's PxWebAPI 2.0
- 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
- Built-in API rate limit controls
- Built-in error handling and intelligent response parsing
- Multilanguage support (Swedish/English)
Requirements
- Python 3.7 or higher
- Dependencies:
- pandas >= 1.0.0
- requests >= 2.25.0
Installation
Install the latest version:
pip install pxstatspy
For development installation:
git clone https://github.com/xemarap/pxstatspy.git
cd pxstatspy
pip install -e .
Quick Start
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://statistikdatabasen.scb.se/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"]
}
)
Contributing
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
Resources
License
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses the following open source resources:
The full license texts are available in the LICENSES directory.
Acknowledgments
- Statistics Sweden for providing the PxWebAPI 2.0
- Contributors to the project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pxstatspy-1.0.0.tar.gz.
File metadata
- Download URL: pxstatspy-1.0.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b37e9485005dbe0fc2ed53fe2b42170168fcd943dc93c601f60d0ce30229d75
|
|
| MD5 |
d94ff69707a61496e82a476c49f5494f
|
|
| BLAKE2b-256 |
b016e1b6dfdc1d1cf96619b805fb62be6cf7d5b622b7adce102f9f121ee43654
|
File details
Details for the file pxstatspy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pxstatspy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab9ad65bd85b6b9b069d3e80416a22a32cc6211471fdaaf199982a78b5f46f1b
|
|
| MD5 |
18d997d01261199cae52c7fdcc0307e1
|
|
| BLAKE2b-256 |
2fc7b09897be16647753cc18a9a71dc38d692a39161ab9e70aa5e22f869d1839
|