sciunto-org / python-bibtexparser

Bibtex parser for Python 3
https://bibtexparser.readthedocs.io
MIT License
474 stars 132 forks source link

Using this project to generate .bib files #399

Closed claell closed 1 year ago

claell commented 1 year ago

This is more a question. For another project, I am looking for a python library to write .bib files.

What I want to achieve is to generate .bib files from other sources. For that, only the writing side and data model of this library seem to be needed.

However, I didn't really find documentation about how to create library entries from scratch and how to edit them.

Some help would be appreciated (also an answer on the question whether this project is good for that purpose or whether I should go for some other solution).

claell commented 1 year ago

I think I found some starting point in the meanwhile (after installing the library and playing around a bit):

import bibtexparser
from bibtexparser import *

bib_library = bibtexparser.Library()

fields = []

fields.append(bibtexparser.model.Field("author", "test"))

entry = bibtexparser.model.Entry("article", "test", fields)

bib_library.add(entry)

print(bib_library.entries_dict)

From that, the library can be used as input for the write function.

So if there is nothing to add by the maintainers, this can be closed.

MiWeiss commented 1 year ago

Great, I'll close the issue as mentioned.

One note on your code snippet: Instead of print(bib_library.entries_dict), you may want to use bibtexparser.write_file("my_new_file.bib", bib_library) to create the .bib file.

claell commented 1 year ago

Yup, I was aware that my code didn't contain the actual writing part. Thanks for the reference, so it's also documented here!