Skip to main content

Befolkning Fagfunksjoner

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

Collection of python functions used in statistics production in the Division for Population Statistics at Statistics Norway.

Features

  • TODO

Requirements

  • TODO

Installation

poetry add ssb-befolkning-fagfunksjoner

Usage

Reference Guide

The library's utilities are grouped into structured submodule namespaces. Here is a quick reference cheat sheet:

Module Namespace Key Utilities Description
date_tools EventParams, validate_reference_date, get_last_day_of_month Prompts, validations, calendar windows, and formatting of statistical dates.
demographics birth_rates, dublettsjekk Calculations of birth rates, cohort analyses, and duplicate checks.
io read_csv_case_indep_pd, read_csv_case_indep_pl Fast Pandas/Polars case-insensitive loaders for register CSVs.
klass load_komm_nr, map_to_country_codes, load_verdensinndeling Direct integrations with SSB's KLASS system for region/country classification mapping.
logs config_logging Standardized logging setup for both terminal display and Cloud/Local file-logging (including SSB headers).
sas ManagedSASsession Session setups and helpers to safely run migrations and SAS operations on Dapla.

EventParams

EventParams contains logic for:

  • Prompting and validating parameters for event periods
  • Creating period labels
  • Computing calendar window for the chosen period
  • Exposing event parameters for parameterising SQL queries

Supported period types are:

  • year
  • halfyear (1-2)
  • quarter (1-4)
  • month (1-12)
  • week (ISO week, 1-53)

The class can be constructed with explicit arguments in code:

from ssb_befolkning_fagfunksjoner import EventParams

# Example: March 2024, with default wait period (1 month, 0 days)
params = EventParams(
    year=2024,
    period_type="month",
    period_number=3,
    specify_wait_period=False,  # default; can be omitted
)

If input arguments are omitted, the user will be prompted:

  • year: prompts for an integer between 1900 and current year
  • period_type: prompts for a valid period type
    • Accepts both full names ("quarter", "month", etc.) and single-letter abbreviations ("q", "m", etc.)
  • period_number: prompted only when needed, with appropriate range checks (e.g. 1-12 for months)
from ssb_befolkning_fagfunksjoner import EventParams

# Will ask the user for missing values in the terminal
params = EventParams()

Once the class is constructed, get the period label as follows:

# Example: March 2024, with default wait period
period_label = params.period_label
# "p2024-03"

Get the start and end dates of the period using the window property:

# Example: March 2024, with default wait period
start_date, end_date = params.window
# datetime.date(2024, 3, 1), datetime.date(2024, 3, 31)

Get a dict used for parameterising SQL-queries:

sql_param = params.to_query_params()
# {
#   "start_date": datetime.date(2024, 3, 1),
#   "end_date": datetime.date(2024, 3, 31),
#   "etterslep_start": datetime.date(2024, 4, 1),
#   "etterslep_end": datetime.date(2024, 4, 30)
# }

Demographics

KLASS utils

Kommnr

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, Befolkning Fagfunksjoner is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

Metadata

Release files for ssb-befolkning-fagfunksjoner 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ssb-befolkning-fagfunksjoner 0.3.0
File Size Uploaded
ssb_befolkning_fagfunksjoner-0.3.0.tar.gz 28.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ssb-befolkning-fagfunksjoner 0.3.0
File Interpreter ABI Platform
ssb_befolkning_fagfunksjoner-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.6 kB

Release files / ssb_befolkning_fagfunksjoner-0.3.0.tar.gz

Download URL ssb_befolkning_fagfunksjoner-0.3.0.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bf9f02bc38906cdc2738d4c77033660b0845f075ebbe2f449283c3b4cd38f9e9
BLAKE2b-256 checksum
How to use checksums
590e5aff29fc800973be297499cb9e6ca2a71a3c8dc5c37d78ac888f7353289c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release files / ssb_befolkning_fagfunksjoner-0.3.0-py3-none-any.whl

Download URL ssb_befolkning_fagfunksjoner-0.3.0-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b3bff2d8dbae2dc8d3dda5bb2d3a402ac489c713abd5642aca7ea0bdbb82684
BLAKE2b-256 checksum
How to use checksums
02cc4114f6b886eff25c84d03bebd49a1dead62895a4bbb7ec8df506f5b57e27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page