Skip to main content

py-gesetze

License PyPI Build

Linking german legal norms, dependency-free & GDPR-friendly. py-gesetze automatically transforms legal references into a tags - batteries included.

This project is a Python port of the PHP library php-gesetze.

Installation

It's available from PyPi using pip:

pip install gesetze

Getting started

Using this library is straightforward.

Commandline

Pretty much self-explanatory - otherwise, --help is your friend:

$ gesetze --help
Usage: gesetze [OPTIONS] COMMAND [ARGS]...

  Utilities for indexing & analyzing german legal norms

Options:
  -v, --verbose  Enable verbose mode.
  --version      Show the version and exit.
  --help         Show this message and exit.

Commands:
  analyze  Analyzes legal NORM
  clear    Clears download cache
  scrape   Scrapes legal norms from PROVIDER

Package

The underlying module may also be used directly:

from gesetze import Gesetz, analyze

# Initialize it
obj = Gesetz()

# Configure it
obj.title = 'normal'

# Convert legal references
print(obj.gesetzify('This text references Art. 1 GG.'))

# "This text references <a class="hover:underline" href="https://www.gesetze-im-internet.de/gg/art_1.html" title="Grundgesetz für die Bundesrepublik Deutschland">Art. 1 GG</a>."

print(analyze('§ 433 Abs. 2 BGB'))

# {'norm': '433', 'absatz': '2', 'gesetz': 'BGB'}

Usage

Class Gesetz

__init__(providers: typing.Union[typing.Iterable[str], str])

providers controls the providers (and their respective order) to be used, either some iterable (such as list or tuple) or a single str.

Note: This defaults to all available providers, which is a good overall choice, simply because of the vast array of supported laws. However, possible values are gesetze, 'dejure', 'buzer' and 'lexparency'.

gesetzify(string: str, callback: typing.Callable) -> str

Transforms legal references into HTML link tags

Note: For more flexibility, you may use your own callback method as second parameter of gesetzify. Callbacks are being passed the re.Match object representing matched legal norms. This way, you could highlight them using <strong> tags instead of converting them into a tags. Default: obj.linkify

Example: Inside the callback function, the match for '§ 433 Abs. 2 BGB' (match.group(0)) would give a dictionary like {'norm': '433', 'absatz': '2', 'satz': None, 'nr': None, 'lit': None, 'gesetz': 'BGB'} (eg using match.groupdict()).

Note: For convenience, a Markdown callback is included and may be used like this: obj.gesetzify('your-text', obj.markdownify)

Helpers

analyze(string: str) -> dict

Analyzes a single legal norm

extract(string: str) -> list

Extracts legal norms as list of strings

roman2arabic(string: str)

Converts roman numerals to arabic numerals (static method)

Configuration

The gesetzify command may be configured through the following options:

obj.attributes (dict)

Defines HTML attribute defaults. Default: {'target': '_blank'}

obj.title (False|str)

Controls title attribute. Default: False

Possible values:

  • light: abbreviated law (eg 'BGB')
  • normal: complete law (eg 'Bürgerliches Gesetzbuch')
  • full: official heading (eg '§ 1 Beginn der Rechtsfähigkeit')

Contributing

If you want to get your hands dirty, this will download the repository and install py-gesetze along its dependencies inside a virtual environment, ready for action:

# Clone repository & change directory
git clone https://codeberg.org/S1SYPHOS/py-gesetze && cd py-gesetze

# Set up & activate virtualenv
poetry shell

# Install dependencies
poetry install

Credits

This library is based on ..

  • .. an adapted (and somewhat improved) version of the jura_regex regex package by Philipp Kiersch.
  • .. an adapted (and somewhat modified) version of the gesetze crawler package by Matej Grahovac.

Special Thanks

I'd like to thank everybody that's making free & open source software - you people are awesome. Also I'm always thankful for feedback and bug reports :)

Metadata

Release files for gesetze 1.2.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 gesetze 1.2.2
File Size Uploaded
gesetze-1.2.2.tar.gz 8.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for gesetze 1.2.2
File Interpreter ABI Platform
gesetze-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 MB

Release files / gesetze-1.2.2.tar.gz

Download URL gesetze-1.2.2.tar.gz
Size 8.0 MB
Tags Source
SHA-256 checksum
How to use checksums
56eca6bf5f18fe84e2a694cc443d01027ed46c1112a8ff34ef61f44ffd932e03
BLAKE2b-256 checksum
How to use checksums
3e8bae2aa1d2504536850810181d406f00b774295f2c038c46064b6db73d077c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.4 Linux/5.19.0-76051900-generic

Release files / gesetze-1.2.2-py3-none-any.whl

Download URL gesetze-1.2.2-py3-none-any.whl
Size 8.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c35eedb15df1b6d5ac6b9eee468e60f0461b8fc538ab6a9bd33582f6c2cde978
BLAKE2b-256 checksum
How to use checksums
2422a6ac50a5f0d99e4f773fd952e0b67561c9ab17b6a97ef0fa17f4ae83a5d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.4 Linux/5.19.0-76051900-generic

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

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