Skip to main content

Pacifica Metadata

Project description

Pacifica Metadata Services

Build Status Build status Code Climate Test Coverage Issue Count Docker Stars Docker Pulls Docker Automated build

This is the Pacifica Metadata Services API.

This service provides metadata for objects and relationships between objects. See the metadata model page for a complete listing of objects and relationships between objects.

Installing the Service

Use the Docker Container

docker pull pacifica/metadata

The Docker Compose Way

docker-compose up

The Manual Way

Install the dependencies using the pip command:

pip install pacifica-metadata

Setup the database the default is PostgreSQL.

pacifica-metadata-cmd dbsync

Then, run the code:

pacifica-metadata

The API

The Pacifica Metadata Services API covers the complete object life-cycle: create, read, update, and delete.

The examples in this section demonstrate the life-cycle of the User object using a Pacifica Metadata Services deployment at http://localhost:8121/ (see "Installing the Service" section).

Creating an Object

To create a new User object, start by generating a new file create.json to store the JSON data:

{
  "_id": 127,
  "email_address": "john@doe.com",
  "first_name": "John",
  "last_name": "Doe",
  "middle_initial": "",
  "network_id": "guest"
}

Then, provide the contents of the new file as the body for a HTTP PUT request using the curl command:

curl -X PUT -T create.json 'http://localhost:8121/users'

Reading an Object

To retrieve the JSON data for the User object that was just created, send a HTTP GET request (with the _id attribute as a query parameter) using the curl command:

curl -X GET 'http://localhost:8121/users?_id=127'

The response body is a JSON array of JSON objects. Because the query uses the _id attribute, a primary key, the JSON array contains either zero (no match) or one (match) JSON objects:

[
  {
    "_id": 127,
    "email_address": "john@doe.com",
    "encoding": "UTF8",
    "first_name": "John",
    "last_name": "Doe",
    "middle_initial": "",
    "network_id": "guest",
    "created": 1459204793,
    "deleted": null,
    "updated": 1459204793
  }
]

Optionally, query on any other parts of an object by using its attributes as query parameters, e.g., to query on both the first_name and last_name attributes using the curl command:

curl -X GET 'http://localhost:8121/users?last_name=Doe&first_name=John'

Response bodies for queries on other parts may contain JSON data for more than one match:

[
  {
    "_id": 127,
    "email_address": "john@doe.com",
    "encoding": "UTF8",
    "first_name": "John",
    "last_name": "Doe",
    "middle_initial": "",
    "network_id": "guest",
    "created": 1459204793,
    "deleted": null,
    "updated": 1459204793
  },
  ...
]

Pagination

By default, Pacifica Metadata Services API endpoints respond with JSON data for all matching objects. Hence, the response size, and therefore, the response time is proportional to the number of matches.

To reduce the response time, but still enable access to all matching objects, all Pacifica Metadata Services API endpoints offer a "pagination" capability, where large responses are subdivided into "pages" with a fixed number of matching objects "per page".

For example, 100 matching objects are divided into 4 pages of 25 matching objects per page:

  • Page 1 = Matching objects 1 to 25
  • Page 2 = Matching objects 26 to 50
  • Page 3 = Matching objects 51 to 75
  • Page 4 = Matching objects 76 to 100
  • Page >4 = No matching objects

Use the page_number and items_per_page query parameters to specify the number of pages and the number of matching objects per page, respectively, e.g., to retrieve the 7th page of 10 Users per page using the curl command:

curl -X GET 'http://localhost:8121/users?items_per_page=10&page_number=7'

Updating an Object

To modify a preexisting object, use the query parameters to identify the object (or objects) and then send a HTTP POST request with the JSON data for the modified attributes as the request body, e.g., to modify the network_id attribute, start by generating a new file update.json to store the JSON data:

{
  "network_id": "example"
}

Then, provide the contents of the new file as the body for a HTTP POST request using the curl command:

curl -X POST -T update.json 'http://localhost:8121/users?last_name=Doe&first_name=John'

Finally, verify the modifications by retrieving the most recent version of the object (see "Reading an Object" section), e.g., using the curl command:

curl -X GET 'http://localhost:8121/users?_id=127'

The updated attribute is automatically set to the current time when an object is modified:

[
  {
    "_id": 127,
    "email_address": "john@doe.com",
    "encoding": "UTF8",
    "first_name": "John",
    "last_name": "Doe",
    "middle_initial": "",
    "network_id": "example",
    "created": 1459204793,
    "deleted": null,
    "updated": 1459205143
  }
]

(Soft) Deleting an Object

To mark an object as deleted, i.e., to "soft delete" an object, send a HTTP DELETE request using the curl command:

curl -X DELETE 'http://localhost:8121/users?_id=127'

NOTE Don't worry! The object isn't really deleted.

Finally, verify the "soft delete" by retrieving the most recent version of the object (see "Reading an Object" section), e.g., using the curl command:

curl -X GET 'http://localhost:8121/users?_id=127'

The deleted attribute is automatically set to the current time when an object is "soft deleted":

[
  {
    "_id": 127,
    "email_address": "john@doe.com",
    "encoding": "UTF8",
    "first_name": "John",
    "last_name": "Doe",
    "middle_initial": "",
    "network_id": "example",
    "created": 1459204793,
    "deleted": 1459205341,
    "updated": 1459205143
  }
]

Contributions

Contributions are accepted on GitHub via the fork and pull request workflow. GitHub has a good help article if you are unfamiliar with this method of contributing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pacifica-metadata-0.4.0.tar.gz (336.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pacifica_metadata-0.4.0-py3-none-any.whl (124.5 kB view details)

Uploaded Python 3

pacifica_metadata-0.4.0-py2-none-any.whl (124.5 kB view details)

Uploaded Python 2

File details

Details for the file pacifica-metadata-0.4.0.tar.gz.

File metadata

  • Download URL: pacifica-metadata-0.4.0.tar.gz
  • Upload date:
  • Size: 336.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for pacifica-metadata-0.4.0.tar.gz
Algorithm Hash digest
SHA256 aecd65afdc23f61c140bdd47d056718118cf47fc50483b093ff0f08b9d3c2b2e
MD5 ab28c068a2673746a77c0d776b3f19c0
BLAKE2b-256 41cc4f7da11035bde9b01180fd2e9f558f7f1bf2df6abcbcd6848da7e79a157c

See more details on using hashes here.

File details

Details for the file pacifica_metadata-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pacifica_metadata-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 124.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for pacifica_metadata-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6558f583d216c6a6e8c8c365272b31bd0e8fddbf61f6e4d011094ec4deb73a38
MD5 9f5b4607924dedd26fdac823b5cc9c58
BLAKE2b-256 7983ed50ac4a1a2ccf3773cc0fd5635ddf3a6a8dfdf4e172cb75012fa7025de0

See more details on using hashes here.

File details

Details for the file pacifica_metadata-0.4.0-py2-none-any.whl.

File metadata

  • Download URL: pacifica_metadata-0.4.0-py2-none-any.whl
  • Upload date:
  • Size: 124.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.14

File hashes

Hashes for pacifica_metadata-0.4.0-py2-none-any.whl
Algorithm Hash digest
SHA256 8b4709223cbb9f872d323aac9d2b831f9444b3586e9a64170d1fe3cbff7a573e
MD5 d7dd6f49500cf931418a80dcf438495c
BLAKE2b-256 9989494ae3d4e708f99ba3d5971c9bfb1748460793bc9baf0ba808142bbe3432

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page