Skip to main content

A minimal loader and dumper for bibtex-files

Project description

BlackStyle

Format according to “Tame the BeaST” by Nicolas Markey, Oct. 2009.

  • @TYPE{citekey, key = {value}, ...}, This will be loaded as bib-entry of type TYPE

  • @string{key = {value}, ...}

  • @preamble{value}

Functions

loads

Loads the raw bytes of a bibtex-file into a dictionary and makes only minimal assumptions on the structrue but not on the content.

normalize

Takes the raw bib-dictionary and tries to decode and normalize it. All optionally. It strips away leading, trailing, and consecutive whitespaces. It converts all keys, entrytypes, and citekyes to lowercase. It decodes keys and/or values to ‘’ascii’’.

dumps

Dumps a normalized (all ascii string) bib-dictionary into a bib-file-string.

Example

import minimal_bibtex_io as mbib

# Read bytes, make no assumptions on keys or encoding
with open("minimal_bibtex_io/tests/resources/example.bib", "rb") as f:
    rawbib = mbib.loads(f.read())

# Try to decode to ascii and set keys to lower case
bib = mbib.normalize(rawbib)

entry = {"type": "book", "citekey": "kasperle1887", "fields": {}}
entry["fields"]["title"] = "The hills are green"
entry["fields"]["year"] = 1887
entry["fields"]["whateverkeyiwant"] = "This is only relevant for me."
bib["entries"].append(entry)

# eventually ...
with open("my.bib", "wt") as f:
    f.write(mbib.dumps(bib, indent=4, width=79))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file minimal_bibtex_io_sebastian_achim_mueller-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for minimal_bibtex_io_sebastian_achim_mueller-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d15c121c57a6999abb82809639c5e829eb7083c12ac96857c644f8797eddf65d
MD5 29b11c4b2c9cfeb9bdffc51fa7e23832
BLAKE2b-256 8f7fdb8171d63a218b059caf1976d5ab5fe094df797b43a30a5dc6fbb88d72f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page