<jupyter_start><jupyter_text>Using FAIRshake APIThis notebook walks through using FAIRshake API with coreapi's python implementation, it works just as easily in javascript or any language with a coreapi implementation. Given that swagger is also exposed at , a swagger-based client can *also* be used.For more information, refer to the documentation at https://fairshake.cloud/swagger/Dependencies:`pip install 'git+https://github.com/u8sand/PySwaggerClient.git@v1.0'`<jupyter_code>import pyswaggerclient

url = 'https://fairshake.cloud/'

schema_url = 'https://fairshake.cloud/swagger?format=openapi'

fairshake_client = pyswaggerclient.SwaggerClient(schema_url)<jupyter_output><empty_output><jupyter_text>Step 1. Authentication If you don't already have a user registered with FAIRshake, you need to create one.This can be done manually at .Your API Key is available at **Note**: Authentication is only required if you plan on *creating*/*changing* things. Read-access is available without authentication.<jupyter_code># Put your API Key in this string
api_key = ''<jupyter_output><empty_output><jupyter_text>Now that we have our API key, we can reinstantiate our Client with an authenticated transport layer.<jupyter_code>fairshake_client.update(
    headers={
        'Authorization': 'Token ' + api_key,
    }
)<jupyter_output><empty_output><jupyter_text>We can test that it worked by reading information about the logged in user.<jupyter_code>fairshake_client.actions.auth_user_read.call()<jupyter_output><empty_output><jupyter_text>Step 2. Project, Digital Object, Rubric, Metric Management All elements expose themselves in the same way with a common set of attributes for search and identification with a few extra attributes distinguishing each element.Here, quite simply, is the gist of these data models:```pythonclass Identifiable:  id: int  url: str  title: str  description: str  image: str  tags: str  type: ['', 'any', 'data', 'repo', 'test', 'tool']  authors: Author[]class Project(Identifiable):  passclass DigitalObject(Identifiable):  projects: Project[]  rubrics: Rubric[]class Rubric(Identifiable):  license: str  metrics: Metric[]class Metric(Identifiable):  license: str  rationale: str  principle: str  fairmetrics: str  fairsharing: str```Queries can be made by providing any of the parameters and we'll return the subset of the database which satisfies those parameter constraints. Though you use `title=something` we do a fuzzy search if it makes sense to do so. More find-tuned queries are actually supported by the API but not yet documented which would allow for django-style filters e.g. `title__contains=something`.**Note**: Results are paginated; use `params={'page': n}` to go through pages<jupyter_code># List all projects
fairshake_client.actions.project_list.call()
# List all Digital objects of type Tool
fairshake_client.actions.digital_object_list.call(type='tool')
# Create a metric
metric = fairshake_client.actions.metric_create.call(data=dict(
    title='My Metric',
    description='It has a url',
    type='url',
    tags='my project test',
    license='MIT',
    rationale='https://fairrationals.com/test',
    principle='F',
))
metric_id = metric['id']
metric
# Create a rubric
rubric = fairshake_client.actions.rubric_create.call(data=dict(
  title='My Rubric',
  description='Rubric is great',
  tags='my project test',
  type='tool',
  license='MIT',
  metrics=[
      metric_id,
  ],
))
rubric_id = rubric['id']
rubric
# Create a project
proj = fairshake_client.actions.project_create.call(data=dict(
  url='http://my-objects.com',
  title='My Project',
  description='Project is great',
  tags='my project test',
))
proj_id = proj['id']
proj
# Create a digital object
obj = fairshake_client.actions.digital_object_create.call(data=dict(
  url='http://my-objects.com/00001',
  title='My Object',
  description='Object is great',
  tags='my object test',
  type='tool',
  rubrics=[rubric_id],
  projects=[proj_id],
))
obj_id = obj['id']
obj<jupyter_output><empty_output><jupyter_text>Performing Assessments```pythonclass Assessment:  project: Project  target: DigitalObject  rubric: Rubric  methodology: ['self', 'user', 'auto', 'test']  answers: Answer[]class Answer:  metric: Metric  answer: float  0~1 quantified metric satisfaction  comment: str  url_comment: str```<jupyter_code># Create an assessment
fairshake_client.actions.assessment_create.call(data=dict(
  project=proj_id,
  target=obj_id,
  rubric=rubric_id,
  methodology='test',
  answers=[
      {
          'metric': metric_id,
          'answer': 1.0,
          'url_comment': 'http://my_url.com',
      },
  ],
))<jupyter_output><empty_output><jupyter_text>Obtaining the score of a Digital Object<jupyter_code>score = fairshake_client.actions.score_list.call(data=dict(target=obj_id))
score<jupyter_output><empty_output><jupyter_text>Displaying FAIR insignia The insignia client library exposes a function, `build_svg_from_score` which accepts a container and the query dict.<jupyter_code>import json
from IPython.display import display, HTML
HTML("""
<div
    id="insignia"
    data-target="%s"
    style="width: 40px; height: 40px; border: 0px solid black" />
""" % (obj_id))
%%javascript
require(['https://fairshake.cloud/static/scripts/insignia.js'], function(insignia) {
    var element = document.getElementById('insignia')
    insignia.build_svg_from_score(
        element,
        { target: element.getAttribute('data-target') }
    )
})<jupyter_output><empty_output><jupyter_text>Delete test objects<jupyter_code># Delete your account and associated objects
result = fairshake_client.actions.digital_object_delete(data=dict(id=obj_id))
display(result)
result = fairshake_client.actions.project_delete(data=dict(id=proj_id))
display(result)
result = fairshake_client.actions.rubric_delete(data=dict(id=rubric_id))
display(result)
result = fairshake_client.actions.metric_delete(data=dict(id=metric_id))
display(result)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11122261247700284, 'fraction_numerical': 0.003177788927914367, 'mean_word_length': 5.8342857142857145, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '242375', 'license': 'Apache-2.0', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1809, 'n_words': 511, 'path': 'scripts/tutorial-pyswaggerclient.ipynb', 'repo_name': 'Nitrogen-DCPPC/FAIRshake', 'size': '5979'}