ply-bibtex-parser
A simple ply-based parser for BibTeX
ply is an easy-to-use, pure-Python parser generator. However it's not the most modern or performant tool.
This is mostly an academic exercise into writing a simple parser, but I used it in my personal website in order to parse
a .bib file to identify the different citations and write them back after reformatting
them.
Install
pip install ply-bibtex-parser
Usage
Parsing
The main entry point is through parser:
from ply_bibtex_parser import parser
input = '@article{citekey, author={Smith, Micah J.}, title={Foo bar}}'
parser.parse(input)
# [BibtexEntry(type='article', key='citekey', fields={'author': '{Smith, Micah J.}', 'title': '{Foo bar}'})]
The parser produces a possibly-empty list of BibtexEntry objects. Note that values in
the entry which are usually delimited with braces contain the braces: this makes it easy to
write back the bibtex entry without trying to escape its contents. The caller is responsible
for further parsing the values if they intend to use the string after escaping is performed.
Lexing
You can also use the lexer directly:
from ply_bibtex_parser import lexer
input = '@article{citekey, author={Smith, Micah J.}, title={Foo bar}}'
lexer.input(input)
for tok in lexer:
print(tok)
# LexToken(AT,'@',1,0)
# LexToken(ID,'article',1,1)
# LexToken(ENTRYBEGIN,'{',1,8)
# LexToken(ID,'citekey',1,9)
# LexToken(COMMA,',',1,16)
# LexToken(ID,'author',1,18)
# LexToken(EQUALS,'=',1,24)
# LexToken(VALUE,'{Smith, Micah J.}',1,41)
# LexToken(COMMA,',',1,42)
# LexToken(ID,'title',1,44)
# LexToken(EQUALS,'=',1,49)
# LexToken(VALUE,'{Foo bar}',1,58)
# LexToken(ENTRYEND,'}',1,59)
Development
Install
pip install poetry
poetry install
Check
inv test lint
Limitations
See the TODO notes in ./ply_bibtex_parser/lexer.py and ./ply_bibtex_parser/parser.py.
Metadata
Release files for ply-bibtex-parser 0.1.0
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 | |
|---|---|---|---|---|
| ply-bibtex-parser-0.1.0.tar.gz | 4.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ply_bibtex_parser-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / ply-bibtex-parser-0.1.0.tar.gz
| Download URL | ply-bibtex-parser-0.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd0ebf310714b666eb52b5d174f72e1c27c13e262d7841faacb499a294d71ecd
|
|
BLAKE2b-256 checksum How to use checksums |
89d578251e0456243c176f6a34ad0ec9d53808dcbfee563d4cde104d0ee79d9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0
|
Release files / ply_bibtex_parser-0.1.0-py3-none-any.whl
| Download URL | ply_bibtex_parser-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e15c03dbe55dba4dbc6ca5e3a7b6bbac11abbd98f135dfa675d15857dac279ce
|
|
BLAKE2b-256 checksum How to use checksums |
d2caf60f829349cf8a48b536e698a920ce65f8c3fc3bbdb1adbf7811549ac47a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.3 Darwin/19.6.0
|
Security for ply-bibtex-parser 0.1.0
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.