pymarc v5.0.0

112 views
Skip to first unread message

Ed Summers

unread,
May 1, 2023, 10:20:04 AM5/1/23
to pym...@googlegroups.com
v5.0.0 of pymarc was just released to PyPI. It is the first major version release since v4.0.0 in February of 2020. v5.0.0 adds several backwards incompatible changes that improve pymarc's usability, but may require you to update your code when upgrading from 4.2.2. Please read on for the details.

== Subfields ==

The Field.subfields property is now a list of Subfield named tuples:

[(code, value), (code, value)]

instead of a flat list of strings:

[code, value, code, value].

Subfield data can be accessed using the .code and .value properties, and are constructed using:

Subfield(code=code, value=value)

The old style of creating subfields is no longer supported. Attempting to pass a list of strings to the `subfields` parameter for the `Field` constructor will raise a `ValueError`. Here's an example of creating a record with a 245 field:

>>> from pymarc import Record, Field, Subfield
>>> record = Record()
>>> record.add_field(
Field(
tag='245',
indicators=['0', '1'],
subfields=[
Subfield(code='a', value='The pragmatic programmer : '),
Subfield(code='b', value='from journeyman to master /'),
Subfield(code='c', value='Andrew Hunt, David Thomas.')
]
)
)

To access the third subfield's value from the record's 245 field:

>>> record['245'].subfields[2].value
'Andrew Hunt, David Thomas.'

Previously that would have looked like:

>>> record['245'].subfields[5]
'Andrew Hunt, David Thomas.'

Your code may not be effected since it is still possible to access subfields as a dictionary:

>>> record['245']['c’]
'Andrew Hunt, David Thomas.'

== Unicode ==

By default pymarc will read records and convert field data to Unicode in order to simplify the most common use case where data is being extracted from MARC data and used elsewhere (JSON, databases, etc). However pymarc also supports writing MARC with pymarc.MARCWriter.

When writing records that have been converted to Unicode the serialized MARC record will contain UTF-8 data. Prior to v5.0.0 the record leader (position 9) was not updated to indicate that the encoding was UTF-8. v5.0.0 changes this by automatically setting leader position 9 when writing records. This change should reduce the need to use force_utf8 when reading data with pymarc.MARCReader since the leader will be properly coded.

== Record Properties ==

`pymarc.Record` objects make it easy to access commonly desired information without needing to know the details of which MARC fields and subfields they are coming from, including: title, author, subjects, location, publisher, pubyear, series, uniformtitle, issn_title, isbn, issn, issnl, and sudoc. Prior to v5.0.0 these were methods, but since they are read-only in v5.0.0 they have been converted into properties.

So code that previously looked like:

```
>>> record.title()
'The pragmatic programmer : from journeyman to master /'
```

will now need to look like:

```
>>> record.title
'The pragmatic programmer : from journeyman to master /'
```

== Thanks! ==

Many thanks to the following contributors who motivated for, designed and implemented these improvements:

- Andrew Hankinson
- David Dowling
- Jon Stroop
- Svetlana Koroteeva
- Dan Scott
- Geoffrey Spear
- Andy Kohler

🛠🌹📚

Ed Summers

unread,
May 1, 2023, 10:24:54 AM5/1/23
to pym...@googlegroups.com
… if the formatting of my previous email seemed wonky please see the v5 release notes on gitlab:

https://gitlab.com/pymarc/pymarc/-/releases/v5.0.0

//Ed

Andrew Hankinson

unread,
May 1, 2023, 10:26:32 AM5/1/23
to pymarc Discussion
Fantastic! Thank you!

Tomasz Kalata

unread,
May 1, 2023, 10:35:29 AM5/1/23
to pym...@googlegroups.com
Great work! Thank you Andrew and all contributors.

--
You received this message because you are subscribed to the Google Groups "pymarc Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymarc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymarc/03f7e587-cb5a-4387-968c-edd4869728can%40googlegroups.com.


--
Tomasz Kalata
Assistant Director, Cataloging

BookOps

The New York Public Library & Brooklyn Public Library

Reply all
Reply to author
Forward
0 new messages