Ed Summers
unread,May 1, 2023, 10:20:04 AM5/1/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
🛠🌹📚