Giter Club home page Giter Club logo

osdupy's Introduction

osdupy

A simple python client for the OSDU data platform.

Contents

Clients

Choose the client that best meets your needs. The same methods are all supported for each.

SimpleOsduClient

BYOT: Bring your own token. Great for backend service or business logic that supplements a front-end application.

This client assumes you are obtaining a token yourself (e.g. via your application's login form or otheer mechanism. With this SimpleOsduClient, you simply provide that token. With this simplicity, you are also then respnsible for reefreeshing the token as needed and re-instantiating the client with the new token.

AwsOsduClient

Requires: boto3==1.15.*

Good for batch tasks that don't have an interactive front-end. Token management is handled with the boto3 library directly through the Cognito service. You have to supply additional arguments for this.

Currently supported methods

  • search
    • query
    • query_with_paging
  • storage
    • query_all_kinds
    • get_record
    • get_all_record_versions
    • get_record_version
    • store_records
    • delete_record
  • delivery
    • get_signed_urls

Installation

pip install osdupy

Usage

Instantiating the SimpleOsduClient

If environment variable OSDU_API_URL is set, then it does not need to be passed as an argument. Otherwise it must be passed as keyword argument.

from osdu.client.simple import SimpleOsduClient

data_partition = 'opendes'
token = 'token-received-from-front-end-app'

# With env var `OSDU_API_URL` set in current environment.
osdu = SimpleOsduClient(data_partition, token)

# Without env var set.
api_url = 'https://your.api.base_url.com'
osdu = SimpleOsduClient(data_partition, token, api_url=api_url)

Instantiating the AwsOsduClient

The only required argument is data_partition. If your environment variables (below) have been set, then client can be instantiated with only data_partition as an argument. Environment variables:

  1. OSDU_API_URL
  2. OSDU_CLIENT_ID
  3. OSDU_USER
  4. OSDU_PASSWORD
  5. AWS_PROFILE
from osdu.client.aws import AwsOsduClient

data_partition = 'opendes'

osdu = AwsOsduClient(data_partition)

If you have not set the above environment variales—or you have only set some—then you will need to pass any undefined as args when instantiating the client.

from getpass import getpass
from osdu.client.aws import AwsOsduClient

api_url = 'https://your.api.url.com'  # Must be base URL only
client_id = 'YOURCLIENTID'
user = '[email protected]'
password = getpass()
data_partition = 'yourpartition'
profile = 'osdu-dev'

osdu = AwsOsduClient(data_partition,  
    api_url=api_url,  
    client_id=client_id,  
    user=user,  
    password=password,
    profile=profile)

Using the client

Below are just a few usage examples. See integration tests for more copmrehensive usage examples.

Search for records by query

query = {
    "kind": f"opendes:osdu:*:*"
}
result = osdu.search.query(query)
# { results: [ {...}, .... ], totalCount: ##### }

Search with paging

For result sets larger than 1,000 records, use the query with paging method.

page_size = 100 # Number of records per page (1-1000)
query = {
    "kind": f"opendes:osdu:*:*",
    "limit": page_size
}
result = osdu.search.query_with_paging(query)

# Iterate over the pages to do something with the results.
for page, total_count in result:
    for record in page:
        # Do stuff with record...

Get a record

record_id = 'opendes:doc:123456789'
result = osdu.storage.get_record(record_id)
# { 'id': 'opendes:doc:123456789', 'kind': ..., 'data': {...}, 'acl': {...}, .... }

Upsert records

new_or_updated_record = './record-123.json'
with open(new_or_updated_record, 'r') as _file:
    record = json.load(_file)

result = osdu.storage.store_records([record])

osdupy's People

Contributors

pbradshawusc avatar puremcc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.