Skip to main content

narrative

Latest PyPI version Python Poetry CI

A small Python package for splitting text into dialogue and narrative.

Installation

narrative is available on PyPI. Simply install it with pip:

pip install narrative

Usage

narrative splits a piece of prose into narrative and dialogue components. The main function split() will return a dict containing both narrative and dialogue components:

>>> import narrative
>>> text = '"Hello," he said. "How are you today?"'
>>> narrative.split(text)
{'dialogue': ['"Hello,"', '"How are you today?"'], 'narrative': ['', ' he said. ', '']}

There are two other helper functions as well.

get_dialogue() returns only the dialogue components:

>>> narrative.get_dialogue(text)
['"Hello,"', '"How are you today?"']

get_narrative() returns only the narrative components:

>>> narrative.get_narrative(text)
['', ' he said. ', '']

Note: The empty strings are a feature of Python's split() function. See Why are empty strings returned in split() results? for an explanation.

British Style

Each function accepts a second parameter of a regular expression used to parse out the dialogue. This defaults to narrative.DIALOGUE_RE, which follows the American standard of using double quotes for initial quotes. narrative now includes a second regular expression, narrative.BRITISH_DIALOGUE_RE, which follows the British style of using single quotes for initial quotes. Simply use it as the second parameter for any function:

>>> import narrative
>>> narrative.split(text, narrative.BRITISH_DIALOGUE_RE)
>>> …
>>> narrative.get_dialogue(text, narrative.BRITISH_DIALOGUE_RE)
>>> …
>>> narrative.get_narrative(text, narrative.BRITISH_DIALOGUE_RE)
>>> …

Metadata

Release files for narrative 1.2.1

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

Source distribution (sdist)

Source distribution for narrative 1.2.1
File Size Uploaded
narrative-1.2.1.tar.gz 14.8 kB Details

Built distribution (wheel)

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

Total release size: 30.3 kB

Release files / narrative-1.2.1.tar.gz

Download URL narrative-1.2.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dc746a97fdc5dc0dd3d9e1de8e526be7ddd02f9c6e71e26213f6a78c249467af
BLAKE2b-256 checksum
How to use checksums
471878c82e186efb79461382cfca73e89e166c0d50cab0f391c83a7558cc1e1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

Release files / narrative-1.2.1-py3-none-any.whl

Download URL narrative-1.2.1-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
882097e9983d5ed2c33f88060e7a28b51ecbacbad68d44da8a0436f0832cec8d
BLAKE2b-256 checksum
How to use checksums
aa8aa794fd30c3e92ecb65860fd82ec7f5b7132aa09a7a2a2fb0a2b13b668775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

1.2.1 This release

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

1.0.1

2 release files

1.0.0

2 release files

0.1.2

2 release files

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