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.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.4.0
File Size Uploaded
ssb_befolkning_fagfunksjoner-0.4.0.tar.gz 28.6 kB Details

Built distribution (wheel)

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

Total release size: 62.4 kB

Release files / ssb_befolkning_fagfunksjoner-0.4.0.tar.gz

Download URL ssb_befolkning_fagfunksjoner-0.4.0.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5a110c474227d782470e77082abe2b9274f76f264ace3fac41712e251d1c5e0d
BLAKE2b-256 checksum
How to use checksums
b7b9f23c877f0caf5b9e9ad16a8e5b3182dbcaf8a82f49b36d4307ee77e44398
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 Sep 29, 2026.

Transparency log

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

Download URL ssb_befolkning_fagfunksjoner-0.4.0-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d63ee70fccd0d51862712f980b43cb8b9bccc46084ded14c9e42407eb32ba669
BLAKE2b-256 checksum
How to use checksums
874f14a3705ea6d2d124ed1f26d70d3a7b70932e2a7f93686763a285e73be291
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 Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

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