Question: I have created a script which scrapes many pdfs for abstract and keywords. I also have a collection of bibtex-files in which I want to place the texts I've extracted. What I'm looking for is a way of adding elements to the bibtex files. 

I have written a short parser: 

```
#!/usr/bin/python
#-*- coding: utf-8

import os
from pybtex.database.input import bibtex

dir_path = "nime_archive/nime/bibtex/"
num_texts = 0

class Bibfile:
  def __init__(self,bibs):
    self.bibs = bibs
    for a in self.bibs.entries.keys():
      num_text += 1
       print bibs.entries[a].fields['title']
       #Need to implement a way of getting just the nime-identificator
       try:
         print bibs.entries[a].fields['url']
       except:
         print "couldn't find URL for text: %s " % a

    print "creating new bibfile"

bibfiles = []
parser = bibtex.Parser()

for infile in os.listdir(dir_path):
    if infile.endswith(".bib"):
      print infile
      bibfiles = Bibfile(parser.parse_file(dir_path+infile))

```

My question is if there is possible to use Pybtex to add elements into the existing bibtex-files (or create a copy) so I can merge my extractions with what is already available. If this is not possible in Pybtex, what other bibtex parser can I use?

Answer: 
I've never used pybtex, but from a quick glance, you can add entries. Since `self.bibs.entries` appears to be a `dict`, you can come up with a unique key, and add more entries to it. Example:

```
key = "some_unique_string"
new_entry = Entry('article',
        fields={
            'language': u'english',
            'title': u'Predicting the Diffusion Coefficient in Supercritical Fluids',
            'journal': u'Ind. Eng. Chem. Res.',
            'volume': u'36',
            'year': u'1997',
            'pages': u'888-895',
        },
        persons={'author': [Person(u'Liu, Hongquin'), Person(u'Ruckenstein, Eli')]},
    )
self.bibs.entries[key] = new_entry

```

(caveat: untested)

If you wonder where I got this example form: have a look in the `tests/` subdirectory of the source of pybtex. I got the above code example mainly from `tests/database_test/data.py`. Tests can be a good source of documentation if the actual documentation is lacking.
.data.add\_entry(key, entry) works for me. Here I used an entry manually created (taken from Evert's example) but you can copy an existing entry from another bib that you're also parsing.

```
   from pybtex.database.input.bibtex import Parser
   from pybtex.core import Entry, Person

   key = "some_unique_string"

   new_entry = Entry('article',
           fields={
               'language': u'english',
               'title': u'Predicting the Diffusion Coefficient in Supercritical Fluids',
               'journal': u'Ind. Eng. Chem. Res.',
               'volume': u'36',
               'year': u'1997',
               'pages': u'888-895',
           },
    persons={'author': [Person(u'Liu, Hongquin'), Person(u'Ruckenstein, Eli')]},
       )

   newbib_parser = Parser()
   newbib_parser.data.add_entry(key, new_entry)
   print newbib_parser.data

```