Skip to main content

bible-ref-py

bible-ref-py is a Python 2 and Python 3 compatible package and regular expression library for validating, extracting and normalizing biblical references from texts.

bible-ref-py is built by Beatitud developers, on top of python-scriptures library, initially implemented by David Davis (Copyright (c) 2010-2015).

Typical usage is as follows:

from scriptures.text import Text
string = "Le service est le billet à présenter à l’entrée des noces éternelles. Ce qui reste de la vie au seuil de l’éternité, ce n’est pas ce que nous avons gagné, mais ce que nous avons donné (cf. Mt 6, 19-21 ; 1Co 13, 8)"
text = Text(string, language='fr', canon='catholic')
text.extract_refs(guess=True)
# [<Ref(Matthieu 6:19-21)>, <Ref(I Corinthiens 13:8)>]

Range validation is performed automatically and invalid references are not extracted.

from scriptures.reference import Reference
Reference(book='Rom', chapter=2, verse=30).is_valid()
# False
Reference(book='Rom', chapter=3, verse=23).is_valid()
# True

Single verse number references can be guessed, according to three rules:

  • If there is a complete reference in the same sentence, before, we suppose the single verse refers to the same books and chapters than this complete reference
  • Else, if there is a complete reference in the same paragraph, before, we suppose the single verse refers to the same books and chapters than this complete reference
  • Else, if there is a complete reference in the text, in the previous paragraphs, we suppose the single verse refers to those books and chapters
from scriptures.text import Text
string = "Les disciples « sortirent à la rencontre de l’époux » (Mt 25, 1). Puis : « Voici l’époux, sortez à sa rencontre ! » (v. 6)." 
text = Text(string, language='fr', canon='catholic')
text.extract_refs(guess=True)
# [<Ref(Matthieu 25:1)>, <Ref(Matthieu 25:6)>]

Installation

To install, simply run the script with the install command:

$ pip install beatitud-scriptures

Or just put the scriptures package somewhere on the Python path.

API

Return Values

When a "scripture reference" is returned, it is always an object with five attributes consisting of:

  • book
  • chapter
  • verse
  • end_chapter
  • end_verse
from scriptures.reference import Reference
ref = Reference(book='Rom', chapter=2, verse=30)
print(ref.book)
# Romans
print(ref.chapter)
# 2

Regular Expressions

There are two compiled regular expression patterns exposed by this package.

book_re

Match a valid abbreviation or book name.

Examples:

from scriptures.canons import get_canon
import re
canon = get_canon(name="catholic")
re.findall(canon.book_re, 'Matt test Ecclesiastes and 2 peter')
# ['Matt', 'Ecclesiastes', '2 peter']    

scripture_re

Match a scripture reference pattern from a valid abbreviation or book name.

Examples:

from scriptures.text import Text
import re
txt = Text("", language="en", canon="catholic")
re.findall(txt.scripture_re, 'Matt 3 & Acts 1:2-3 Rev 2:1-3:2')
# [('Matt', '3', '', '', ''), ('Acts', '1', '2', '', '3'),
# ('Rev', '2', '1', '3', '2')]

Canons

This library currently provides the following canons:

  • catholic - scriptures.canons.catholic.Canon
  • protestant - scriptures.canons.protestant.Canon
  • deuterocanon - scriptures.canons.deutercanon.Canon
  • kjv1611 - scriptures.canons.kjv1611.Canon

Usage

To use the additional texts, simply instantiate the text object and use the api functions and regular expressions on the new instance.

Example

from scriptures.canons.catholic import Canon
cc = Canon(language='en')
print(cc.books)
# {'gn': {
#                'en': ('Genesis', 'Gen', 'Gen(?:esis)?'),
#                'fr': ('Genèse', 'Gn', 'Gen(?:èse)?'),
#                'chapters':
#                    [31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38, 18, 34, 24, 20, 67, 34, 35,
#                     46, 22, 35, 43, 55, 32, 20, 31, 29, 43, 36, 30, 23, 23, 57, 38, 34, 34, 28, 34, 31, 22, 33, 26]
#  },
#  ...}

Custom Canons

The library makes makes extending the library through custom texts trivial through additional modules. Please consider contributing your text modules to this project by creating canons under scriptures/canons/ and submitting a pull request.

Creating a New Canon

To create a new Canon,

  1. Create a class that inherits from scriptures.base.CanonBase
  2. Implement the "books" dictionary
  3. Instantiate your new canon and use it

Test Suite

Unit tests are provided to verify chapter and verse style normalization, output formatting, and book names and abbreviations.

To run the test suite, cwd to just outside of the scriptures package and:

$ python -m unittest discover

Metadata

Release files for beatitud-scriptures 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for beatitud-scriptures 4.0.0
File Interpreter ABI Platform
beatitud_scriptures-4.0.0-py3-none-any.whl Python 3 none any Details
beatitud_scriptures-4.0.0-py2-none-any.whl Python 2 none any Details

Total release size: 78.2 kB

Release files / beatitud_scriptures-4.0.0-py3-none-any.whl

Download URL beatitud_scriptures-4.0.0-py3-none-any.whl
Size 39.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f37391bb4e9448f0dd0874466c7648bcb1574b4eb3299d6744d64a6eb38776b7
BLAKE2b-256 checksum
How to use checksums
2f1fea1114fdeeecc63a0a2b9281911402c70e06a6ae99e2dff3a1a6aa2def97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

Release files / beatitud_scriptures-4.0.0-py2-none-any.whl

Download URL beatitud_scriptures-4.0.0-py2-none-any.whl
Size 39.1 kB
Tags Python 2
SHA-256 checksum
How to use checksums
42c6a7d4962e5586af916814b02111a4221f98dcb5de617638b52279d5f89f3a
BLAKE2b-256 checksum
How to use checksums
aefdcc9784cf530b7de893911750bdcd122b3809e238bb2093dfff1dba088263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

Release history Release notifications | RSS feed

This release

4.0.0 This release

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