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

To install the core library:

poetry add ssb-befolkning-fagfunksjoner

If you need SAS session support (which requires Java and a SAS installation), install the optional sas extra:

poetry add ssb-befolkning-fagfunksjoner -E sas

(If using pip, use pip install ssb-befolkning-fagfunksjoner[sas])

Usage

Optional features are imported identically to standard modules, but will raise a detailed ImportError pointing to the required extra if you attempt to use them without installing it first.

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

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.4.2
File Size Uploaded Provenance Actions
ssb_befolkning_fagfunksjoner-0.4.2.tar.gz 29.2 kB With provenance Details for ssb_befolkning_fagfunksjoner-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 63.9 kB

Release files / ssb_befolkning_fagfunksjoner-0.4.2.tar.gz

Download URL ssb_befolkning_fagfunksjoner-0.4.2.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e317596d8eb7f518faac090de77c409cfdbaf677dc33741ea5945cdbd6cb9457
BLAKE2b-256 checksum
How to use checksums
04c1c0a6b160741642d6b7ef418024a4ccb6a0594e3ca704898d6300cd86a377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 26, 2026.

Transparency log

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

Download URL ssb_befolkning_fagfunksjoner-0.4.2-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1eb9f4587e5b71f52eebace4d7183e42e60bf2a27fd060f6c84cd3788c1f3c67
BLAKE2b-256 checksum
How to use checksums
04de567f5cc6aaf61bffc8d6b602556715e439be5090e65a8768e80906e9bffe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 26, 2026.

Transparency log

Security for ssb-befolkning-fagfunksjoner 0.4.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ssb_befolkning_fagfunksjoner-0.4.2.tar.gz

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 Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files Full provenance

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