Skip to main content

A Python wrapper for the Statistics Sweden PxWebAPI 2.0

Project description

Logo

PxStatsPy

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

Python Versions License

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.

  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.

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


Download files

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

Source Distribution

pxstatspy-1.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

pxstatspy-1.0.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file pxstatspy-1.0.1.tar.gz.

File metadata

  • Download URL: pxstatspy-1.0.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for pxstatspy-1.0.1.tar.gz
Algorithm Hash digest
SHA256 25877d0612734ae9308f565dca7fdef6c8027b8420c328130151552947a097b3
MD5 2c231cca5ab0b70f3faa92b429748ca1
BLAKE2b-256 8e10afe1e990fe1dd703079636980adf084d69480bbf2efe05eccf945bf6b8f5

See more details on using hashes here.

File details

Details for the file pxstatspy-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pxstatspy-1.0.1-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

Hashes for pxstatspy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd1291099ead679afbc36bf5c03ce4f6b8d2a673183fd2261c6ba04e3df6e59
MD5 835c61d8de112059635600453710651b
BLAKE2b-256 bae9ab6a55d1c70a3eb5ff6f3bcd49bfe8480fd60ee16b1e48d8950830aeeb39

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 Pingdom Monitoring Sentry Error logging StatusPage Status page