Skip FOLIO Project Navigation

how to transfer metadata from MARC to DC using Python?

Dear professors,I‘m a Chinese student and I’m interested in FOLIO,I have read the code document in GitHub, but I have meet some troubles about it.I plan to do a experiment transfer metadata from MARC to DC using Python,with the metadata module in FOLIO, please tell me how should I prepare and do?Thank u!
I think that I can use OKAPI to import module to my Python , is right? But I don’t know how to do.:sweat_smile:

Hello, @danke. Thank you for your interest in the FOLIO project. I need to ask a question before pointing you in the right direction. Are you creating a new Okapi module or are you writing a program to interact with the Okapi modules that are already in the system? Creating a new Okapi module in Python would be challenging because we do not have examples you could follow. You would need to implement all of the requirements for an Okapi module yourself. (For the Java programming language, the RAML Module Builder utility does this for you.)

If you are writing a Python program that interacts with Okapi modules, then you would be making HTTP calls to Okapi using something like the Python Requests library. Something like this would get you started:

import requests

def okapi_auth(okapi_endpoint, username, password, tenant):
    """
    Logs into the Okapi tenant

    Parameters:
    okapi_endpoint (string): URL to the Okapi endpoint
    username (string): Username in the Okapi tenant
    password (string): Password for the Username
    tenant (string): Tenant identifier

    Returns:
    Okapi auth token, a Java Web Token supplied by Okapi (string)
    """
    headers = {"X-Okapi-Tenant": tenant}
    payload = {
        "username" : username,
        "password" : password
    }
    r = requests.post(okapi_endpoint + '/authn/login', 
                      headers=headers, json=payload)
    try:
        r.raise_for_status()
    except requests.exceptions.HTTPError as e:
        print("Error: " + str(e))

    return r.headers['x-okapi-token']

# Some constants
okapi_endpoint = "http://localhost:9130"
username = "diku_admin"
password = "admin"
tenant = "<replace with your tenant name>"

# Using the username/password, get the Java Web Token 
okapi_token = okapi_auth(okapi_endpoint, username, password, tenant)

headers = {
    "X-Okapi-Tenant": tenant,
    "X-Okapi-Token": okapi_token,
}

r = requests.get(okapi_endpoint + '/inventory/items', headers=headers)
# now do something with `r.json`

Descriptions of the APIs are on the dev.folio.org website.

Thank you ! I am writing a Python program that interacts with Okapi modules , your suggestion will be very useful .