Skip to content

A comprehensive Python wrapper for the Statistics Sweden PxWebAPI 2.0 (beta), providing easy access to Swedish statistical data.

License

Notifications You must be signed in to change notification settings

xemarap/pxstatspy

Repository files navigation

PxStatsPy (beta)

A comprehensive Python wrapper for the Statistics Sweden PxWebAPI 2.0 (beta), providing easy access to Swedish statistical data.

Python Versions License

Features

  • 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)

Requirements

  • Python 3.7 or higher
  • Dependencies:
    • pandas >= 1.0.0
    • requests >= 2.25.0

Installation

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 .

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://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"]
    }
)

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.

  1. Submit suggestions and report bugs (for faster troubleshooting please enable debug mode and submit the errormessage)
  2. Open a Pull Request
  3. Star the GitHub page

Resources

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • 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.

About

A comprehensive Python wrapper for the Statistics Sweden PxWebAPI 2.0 (beta), providing easy access to Swedish statistical data.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published