Skip to main content

Cofog

Project description

Cofog

PyPI Status Python Version License

Read the documentation at https://cofog.readthedocs.io/ Tests Codecov

pre-commit Black

Introduction

Classification of the Functions of Government (COFOG) is a classification defined by the United Nations Statistics Division. Its purpose is to "classify the purpose of transactions such as outlays on final consumption expenditure, intermediate consumption, gross capital formation and capital and current transfers, by general government" (from home page).

This intention of this package is to serve a convenient way of parsing and interfacing with the classifications.

Data

Data was sourced from the UN's classifications on economic statistics page and parsed into a dictionary that can be found in src/cofog/data.py.

Features

  • Provides the COFOG class to represent a Classification of Functions of Government.
  • Validate COFOG codes through Regular Expressions and presence in the data.
  • Lookup descriptions from codes.
  • Traverse the levels of any given code, with the ability to set a lower level without forgetting the original level.

Requirements

  • Python >=3.8
  • Click >=8.0.1

Installation

You can install Cofog via pip from PyPI:

$ pip install cofog

Usage

Please see the usage page in the docs for full details.

Get started by initialising a new COFOG object with a code. These can be either specified as strings (with and without dots) or integers.

from cofog import COFOG

cofog = COFOG("04.3.6")

# or any of the following
COFOG("0436")
COFOG("436")
COFOG(436)

You can then access the code's description as well as set it to lower level codes.

print(cofog.description)
# Non-electric energy  (CS)
print(cofog.level)
# 3

cofog.set_level(2)
print(cofog.code)
# 04.3
print(cofog.description)
# Fuel and energy

You can also get parent and children codes of any valid code.

print(cofog.get_parent_code())
# 04.3

print(COFOG("07.3").get_children_codes())
# ["07.3.1", "07.3.2", "07.3.3", "07.3.4"]

Contributing

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

License

Distributed under the terms of the MIT license, Cofog 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 heavily inspired by @ellsphillips's govsic package.

This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.

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

cofog-2.0.0.tar.gz (10.5 kB view hashes)

Uploaded Source

Built Distribution

cofog-2.0.0-py3-none-any.whl (9.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page