narrative
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| narrative-1.2.1.tar.gz | 14.8 kB | Without provenance | Details for narrative-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| narrative-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for narrative-1.2.1-py3-none-any.whl |
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
|
Security for narrative 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.