Skip to main content

pkgbuild_parser

Documentation in Spanish

Introduction

pkgbuild_parser is a module written in Python (compatible with Python 3.x) designed to extract information from a PKGBUILD. The main purpose of this module is to provide simple and direct access to the most important fields of a PKGBUILD without relying on external tools or additional libraries.

  • Version: 2.3.0
  • License: MPL-2.0 2026 KevinCrrl
  • Dependencies: None
  • Style: Simplicity, no external dependencies, easy to use

This module allows you to quickly and directly obtain data such as package name, version, description, license, URL, source file, etc.


Contributing to PKGBUILD Parser

See the CONTRIBUTING file.

Classes and usage

from pkgbuild_parser import Parser, InfoDict

parser = Parser(<FILENAME> (String; Default value: "PKGBUILD")
                <ENABLE_CACHE> (Boolean; Default value: True)
                <EXTRA_NAMES> (List of strings; Default value: None))

infodict = InfoDict(<PARSER> (Parser; Not default value)
                    <*INFO_TO_GET> (Strings; Not default value)
                    <MULTILINE> (Boolean; Default value: False)
                    <IGNORE_ERRORS> (Boolean; Default value: False))

Parser Class

  • filename: PKGBUILD path, not directory.
  • enable_cache: enables a dictionary used to save variables and avoid re-parsing.
  • extra_names: list of custom variables to be followed by replacevar.

InfoDict Class

  • parser: Parser used to get the variables.
  • info_to_get: Variables to be followed.
  • multiline: Return lists using multiline or strings using get_base
  • ignore_errors: Ignore all the KeyNotFoundError.

Main functions for the user (Parser class)

Function That returns
get_pkgname() Package name (pkgname) as a string.
get_pkgver() Package version (pkgver) as a string.
get_pkgrel() Release number (pkgrel) as a string.
get_pkgdesc() Package description (pkgdesc) as a string.
get_arch() Package architecture (arch) as a list of strings.
get_url() Main project URL (url) as a string.
get_license() Package license (license) as a list of strings.
get_source() Package source(s) (source) as a list of strings.
get_epoch() Package epoch.
get_install() Install script name
get_full_package_name() Full package name, including epoch, version, and pkgrel.
get_depends() List of the package's dependencies.
get_makedepends() List of the package's build dependencies.
get_optdepends() Dictionary of the package's optional dependencies.
get_options() List of the package's options.
get_checkdepends() List of the package's check dependencies.
get_sums(algorithm) List of the algorithm checksums.
get_validpgpkeys() List of the valid PGP keys.
get_conflicts() List of conflicting packages.
get_provides() List of packages provided.
get_replaces() List of packages it replaces.
get_pkgbase() Base package (pkgbase) as a list.
get_changelog() Changelog filename as a string.
get_groups() List of the package groups.
get_backup() List of the backup files.
get_noextract() List of files to exclude from the extraction.

Note: The internal functions (get_base, multiline, replacevar, processvar and remove_quotes) are intended for module use and do not need to be used by the user, except when you want to create functions that are not in the parser.

Main functions for the user (InfoDict class)

Also, you can use the InfoDict class to create dictionariess from selected information, InfoDict has this methods:

Function That returns
get_dict() dictionary that contains the information requested by the user.
to_json() Converts the dictionary to a JSON format.
write_json(json_name) Writes a file with the provided name that contains the dictionary information in JSON format.

Installation and use

Option 1: AUR

The module is available on the AUR as python-pkgbuild-parser.

Option 2: PyPi

pip install pkgbuild-parser

Basic usage

GitHub example Codeberg example

Error handling

If the PKGBUILD file does not exist, a ParserFileError is raised, which must be caught to prevent the program from failing.

A ParserKeyError can also be raised if getting a value from the PKGBUILD fails, for example, if the license is not declared correctly, and get_license() is called, this exception will be raised.

Limitations and additional notes

  • Starting with version 1.2.0, the parser can replace known variables in a Bash string. For example, if you try to fetch a source file and it is declared in the PKGBUILD as "${url}/package-$pkgver.tar.gz", pkgbuild-parser will be able to recognize these variables, retrieve them, and replace them with their values.
  • The module's goal is to extract only basic information from standard PKGBUILDs, It cannot replace variables it does not recognize, such as variations of known variables, such as "$pkgname%suffix".
  • It works best with PKGBUILDs that follow the Arch Wiki standards.
  • This code doesn't implement a proper parser; it simply reads the PKGBUILD file and extracts the necessary information using various conditions and state logic. However, I try to make it as accurate as possible :)
  • Since version 0.4.0, the module can extract information from arrays or lists, such as depends, makedepends, source, optdepends, license, options, and checkdepends.
  • Since version 1.0.0, functions that return a string no longer include quotes by default.

Metadata

Release files for pkgbuild-parser 2.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 pkgbuild-parser 2.3.0
File Size Uploaded
pkgbuild_parser-2.3.0.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pkgbuild-parser 2.3.0
File Interpreter ABI Platform
pkgbuild_parser-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / pkgbuild_parser-2.3.0.tar.gz

Download URL pkgbuild_parser-2.3.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
07faa6cd42a686816f525afee500cd5f470162a4569487b95ce3ddd18888ed0b
BLAKE2b-256 checksum
How to use checksums
bc2d1d900da68a6111fa180ecc6eaa8a14eb7ae7876883cc7872615d6fe0a1e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / pkgbuild_parser-2.3.0-py3-none-any.whl

Download URL pkgbuild_parser-2.3.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de8b40541d3addcecc7c33f3a576ea95e1e6b8be99ae87280e5e784803ea85cc
BLAKE2b-256 checksum
How to use checksums
ad0b42e2797e11d5f4e51bb3380dd70b5173061a658d0066322a0fd70872e902
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

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