Introduction to pymarc

281 views
Skip to first unread message

Jen Marie Eustis

unread,
Apr 8, 2019, 3:38:45 PM4/8/19
to pymarc Discussion
Hello,

Does anyone have any good resources to learn pymarc? I just began experimenting with it. I've found some basic slides out there from an ALCTS webinar and a preconference. I'm looking for an introduction that goes beyond reading and printing fields and that includes removing fields based on whether that field has a particular second indicator, adding fields also based on a certain indicator, and checking the leader and ensuring those changes are written back into the marc file or a new output file.

Thanks,
Jennifer

Katie Fletcher

unread,
Apr 9, 2019, 12:53:30 PM4/9/19
to pymarc Discussion
Hi Jennifer,

I'd definitely suggest watching the ALCTS webinar - from what I recall it's a two-part webinar, and it gives you a basic grip on the subject. The first thing you need to do is learn basic Python if you haven't already. I run all of my code in Jupyter Notebook, so it's easy to edit and play with. Otherwise, if you do a search for "pymarc" on Github, you'll find some other folks' projects that you can fork and adapt to your own use. Some of the discussions on this site are helpful as well. I haven't found a full-on tutorial outside of the ALCTS webinar. Some example code:


Cheers,
Katie

Jen Marie Eustis

unread,
Apr 9, 2019, 8:23:12 PM4/9/19
to pym...@googlegroups.com
Thank you Katie. I know some Python. I need to look at those webinars. One of the issues I’m having trouble finding is how to work with indicators and then saving those changes to the file, which I guess I have to write everything to an output file. I’ll have a look at the webinar - I think it only goes over outputting to a CSU file..

Best,
Jennifer

Sent from my iPad
--
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.
For more options, visit https://groups.google.com/d/optout.

Alexandra Alisa Provo

unread,
Apr 10, 2019, 11:32:33 AM4/10/19
to pym...@googlegroups.com
Hi Jennifer,

If you'd like to see an example of some scripts that use Pymarc, my predecessor wrote a series of detailed scripts that you might look at for inspiration/solutions: https://github.com/NYULibraries/aco-karms/tree/master/bin

Unfortunately I can't answer many questions about them (I run them, but they're a bit beyond my skillset!)

All best,
Alex
--
Alexandra Provo
Metadata Librarian
Division of Libraries
New York University
20 Cooper Square, 3rd floor
New York, NY 10003

alexand...@nyu.edu
212-992-7534
pronouns: she/her/hers

Edward Summers

unread,
Apr 10, 2019, 11:46:56 AM4/10/19
to pym...@googlegroups.com
It would be really nice to have a little handbook of examples, or even a zine, if anyone has some free time this summer, and some time to spare.

If someone was interested in this and created a crowd funding project I would gladly donate a little bit of money and help spread the word about it.

//Ed
signature.asc

Jennifer Marie

unread,
Apr 10, 2019, 3:16:11 PM4/10/19
to pym...@googlegroups.com
The idea of a handbook of examples Ed would be awesome! Actually that's what I was trying to look for in addition to introduction tutorials. I've done the Intro to Pymarc alcts webinar which is great but I could use more intermediate and advanced examples. There's nothing on indicators and writing to a marc file just csv. 

For the handbook, there's the quick way of just having a repository in GitHub with code snippets. This might be a good place to start as it wouldn't involve a fee. I would be up for working on something like this in the summer.

Jennifer
*********************************************
Jennifer Eustis, jen...@gmail.com

Ben W.

unread,
Apr 10, 2019, 10:40:01 PM4/10/19
to pym...@googlegroups.com
I'd be willing to contribute to such a project as well--great idea!

Dan Scott

unread,
Apr 10, 2019, 10:40:20 PM4/10/19
to pym...@googlegroups.com
So I think shame about the quality of our code often leads to reluctance to offer up examples.

Having no shame, here's a Python 2 script I wrote ages ago that does a bunch of things. A lot of it, probably the wrong way.

The core routine is at https://git.evergreen-ils.org/?p=contrib/Conifer.git;a=blob;f=tools/ebooks/prep_ebook_records.py;h=d9fae25905889061e1026871fb4f96c761e8a785;hb=refs/heads/tools_current#l473 which takes an old record as input, creates a new record, then iterates through every field in the old record, either manipulating the field if it happens to be of interest and then adding the manipulated field to the new record, or just adding a copy of the field to the new record.

I think a (much-simplified) version of this loop-through-the-fields to create a new record approach is probably a common pattern for pymarc scripts that output modified MARC?

On lines 1246 and 1248, it writes out the new record in either MARXML or MARC binary format.

It doesn't look like I do much with indicators, though, other than setting them explicitly or (on line 586) cloning the existing indicators from a field for a new field.

So, if this were simplified massively and rewritten for Python 3 and more recent versions of pymarc, it might be useful...

Dan Scott

unread,
Apr 10, 2019, 11:00:31 PM4/10/19
to pym...@googlegroups.com
Hmm the examples in the pymarc README (https://github.com/edsu/pymarc) and PyPi page( https://pypi.org/project/pymarc/) do show how to write out MARC files, but I seem to recall not finding that info when I was looking for it either.

Possibly because just doing "pip install pymarc" doesn't give you easy access to the README, and "pydoc pymarc" just gives you the...

oh right, "pydoc pymarc" gives you a subset that says that you use record.asMARC21() to write out MARC binary, instead of record.as_marc()!

I'll file a bug / provide a pullrequest for that. Which is something I've meant to do for a long time...

Jennifer Marie

unread,
Apr 11, 2019, 8:20:33 AM4/11/19
to pym...@googlegroups.com
I also found these code examples just yesterday https://github.com/ThursdayPythonCodeClub/Code-Examples/blob/master/ex-tab-delim-2-marc/pymarc-cheat-sheet.py. I'm not sure who created this. 

Jennifer

Geoffrey Spear

unread,
Apr 11, 2019, 8:42:56 AM4/11/19
to pym...@googlegroups.com
Looks like this also came from Alexandra's colleague(s) at NYU. That's a nice find (if also older and using python 2-isms).

Ed Summers

unread,
Apr 23, 2019, 5:12:54 PM4/23/19
to pym...@googlegroups.com
I like that idea too of starting with a repository of examples. Maybe we could conceive of it as a ReadTheDocs project?

https://readthedocs.org/
signature.asc

Ed Summers

unread,
Apr 23, 2019, 5:15:16 PM4/23/19
to pym...@googlegroups.com
I said ReadTheDocs but I was thinking WriteTheDocs :)

https://www.writethedocs.org/
signature.asc

Jennifer Marie

unread,
Apr 25, 2019, 2:44:28 PM4/25/19
to pym...@googlegroups.com
That could be interesting. I don't know anything about either read or write the docs. For the moment, I created a wiki page using my work wiki, https://www.library.umass.edu/wikis/acp/doku.php?id=python&s[]=python. This is only because there's a python learning study group. I'm slowly adding links (it's just a shell now). 

In the long run, it would be great to have more documentation on pymarc with examples.

Jennifer

Paloma Graciani Picardo

unread,
Jul 17, 2019, 3:04:54 PM7/17/19
to pymarc Discussion
Hi there,

just wondering if the development of a handbook of pymarc examples was ever followed up? 

As a pymarc (and python) newbie, it would be incredibly useful.

Paloma

Amy Joseph

unread,
Jul 17, 2019, 6:41:25 PM7/17/19
to pymarc Discussion
I would be interested in contributing to a WriteTheDocs project. I'm roughly 'intermediate' in Python, have dabbled in pymarc and would like to dip my toes into contributing to an open source project. I don't have a deep knowledge of the package, but would be happy to learn and contribute to a documentation project in some way if I can, even if primarily in an admin/editing type way.

Amy

Jennifer Marie

unread,
Jul 17, 2019, 8:24:58 PM7/17/19
to pym...@googlegroups.com
Hi all,

I was hoping to have time this summer to look at different platforms. I started a very small wiki page on my work wiki with links out. I'm unfamiliar with WriteTheDocs. I'd be willing to help out to gather examples. My initial thoughts were to have a couple of wiki pages or do this via github. I realize this might not be something to continue down the road but it provides a platform that hopefully many beginner python and pymarc people have heard of and used.

Any thoughts?

Jennifer

--
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.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages