Giter Site home page Giter Site logo

materials-consortia / optimade-python-tools Goto Github PK

View Code? Open in Web Editor NEW
66.0 7.0 42.0 97.75 MB

Tools for implementing and consuming OPTIMADE APIs in Python

Home Page: https://www.optimade.org/optimade-python-tools/

License: MIT License

Python 98.29% Shell 0.25% Dockerfile 0.12% HTML 0.25% TeX 1.07% Procfile 0.01%
optimade-specification optimade-python optimade-api openapi python optimade

optimade-python-tools's People

Contributors

bot-optimade avatar casperwa avatar dependabot-preview[bot] avatar dependabot[bot] avatar dwinston avatar fawzi avatar fawzi-bot avatar fekad avatar jan-janssen avatar jpbergsma avatar knc6 avatar ltalirz avatar markus1978 avatar merkys avatar ml-evs avatar munahaf avatar pre-commit-ci[bot] avatar rartino avatar shyamd avatar tachyontraveler avatar tpurcell90 avatar wuxiaohua1011 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

optimade-python-tools's Issues

Package structure

  • All of the tests can be stored in a separate module (folder) to reduce clutter ins the package code. inspiration or like fastapi etc.
  • from the root folder, the images can be moved into an images folder and relative path can be used in the markdown.
  • in the future, maybe somebody will have time to write proper documentation for this package :)
optimade-python-tools
| - docs
| - images
| - optimade
    | - filterparser
        | -  grammars
    | - filtertransformers
    | - model
    | - server
| - tests
    | - filterparser
    | - filtertransformers
    | - model
    | - server

Possibly make /info/{endpoint} dynamic

It may be possible to make /info/{endpoint} dynamic in the server.
This is not crucial, but would serve as a good example of how to implement it in one's own OPTiMaDe server implementation.

NOT filter operation of mongo query for complex expressions

This implementation of NOT operation fails in the case when it has been applied for a "complex" expression. Here are some example for the inputs and outputs of a Transformer:

"NOT a>1" -> {'a': {'$not': {'$gt': 1}}}
"NOT a>1 AND b>1" -> {'$and': [{'a': {'$not': {'$gt': 1}}}, {'b': {'$gt': 1}}]}
"NOT (a>1 AND b>1)" -> {'$and': {'$not': [{'a': {'$gt': 1}}, {'b': {'$gt': 1}}]}}

In the case of the last one the transformer gives you a rubish query.

Constraining list/array types in the schema

I don't have time for a full explanation (perhaps @ltalirz/@dwinston can elaborate), but we still have issues in constraining e.g. the lengths of lists in a way that is compatible with both pydantic and FastAPI.

Currently we have conlist which has just been released in pydantic, but has no effect on the generated API pydantic/pydantic/issues/604. It is not clear whether the types inside the conlist can be constrained, as of yet.

We also need a way to constrain lists of lists, e.g. ensuring lattice vectors are always 3x3, and if possible, constraining e.g. cartesian_site_positions to have length nsites, in order to fully validate a JSON response against the spec.

Some additional discussion can be found in the comments to #45.

Support of LHS/RHS expressions

RHS expressions are optional due to the specification by they could be practical. The grammar is already implemented in the version v10.0.x but the implementation of the Transformer may need further testing. Especially if we want to support the following optional rule's as well which is not obvious for me who should be implemented:

identifier <operator> identifier
constant <operator> constant

I think if we want a more elegant implementation we might have to change the grammar as well.

use examples from specs as resources

The current server uses mongo db and mapping of the structures stored in it because it stems from an implementation using it.
I would find it simpler to simply store the structures that need to be returned in a file, and even have one file that gets them simply from the specification.

The current implementation makes it a bit cumbersome, as result it was not updated together with the update of the spec (try to get /structures for example).

I looked into doing it, and I wrote an implementation using tinydb doing that.
It is a larger change so I wanted some feedback before investing time polishing it.

Irregular v0.2.0 publication to PyPI

During a test addition of a GitHub Actions workflow to publish tags on PyPI, I accidentally triggered a publication of v0.2.0 to PyPI via Travis.

We can delete the publication, but can then never publish the under the exact same version.
PyPI recommends releasing a .post1 version instead.

In the end, what do you think should be done?

Maybe it would even make sense to release a new major release (removing v0.2.0 from PyPI), since the work put into this repository since summer is backwards compatible. And it represents a full implementation of the OPTiMaDe spec v0.10.
Even though the spec is not at v1 yet, the implementation here is certainly at that level.

switch to pipenv?

currently, we have a list of required python packages in the setup.py (versions not fixed), and a set of fixed versions in requirements.txt and requirements-optional.txt.

One common issue is that even for fixed packages versions, the versions of dependencies of these packages can still change - this issue is addressed by pipenv.

It turns out we already have a Pipfile in the repository but it isn't mentioned anywhere.

Checklist for OPTiMaDe v0.10.1

@ml-evs: Hijacking this to list features/functionality that are still missing. For detailed discussion of each point, comment on the relevant issue or open one:

  • Recheck meta
    • overhauled in #65
  • /structures/info/ missing? (is now /info/structures)
  • /structures/id missing?
  • "type missing from response" #43
  • Filter parser and Mongo transformer for v0.10.0 of spec
    • in progress at #66
  • Add validator that works on generated openapi.json OR directly from the Python models #7
    • Implemented by #74
  • Add /references (#69)
    • Implemented by #78
  • Implement relationships - test with a structure that has a relationship with a reference (#71)
    • Implemented by #91
  • Add /links endpoint (#89)
    • Implemented by #95
  • Implement HAS _ queries for ALL, ANY etc (#98)
    • Implemented by #173
  • Support pydantic>=1 (#101)
    • Implemented by #110
  • Add index-meta db
    • Implemented by #103
  • Length comparisons #86
  • Update models for structures resources according to new REQUIRED fields (#114)
  • Implement grammar changes
    • Implemented by #112
  • Verify against final version of spec with its recent changes

test how to generate a client from the openapi.json

  • pick a language and generate a client
  • follow instructions in README to set up a server
  • check that the client can communicate with the server
  • write down the steps taken (e.g. in README) so that others can benefit

Minor changes to specification v0.10.1-develop

There are currently minor changes to the specification of v0.10.1-develop.
More may come and should be added below.

Schema / Models

Grammar

Miscellaneous

Implement `warnings`

It would be cool to add something similar to the Exception handlers for Warnings.

Perhaps it could be done with middleware? Or something similar.

What I have in mind is to catch from warnings import warn warnings and add them, as per the OPTiMaDe spec, under meta.warnings.

Central place with a list of queries for transformer tests

This is most definitely for another PR, but as a general question (to whomever happens to read this), would it not be beneficial for future parser developers/contributors that we have a central place with a list of queries, wherein one could also add their parser's expected output for testing? E.g. a python dictionary or importable JSON file?

_Originally posted by @CasperWA in #66 (comment)

Response by @fekad:

That's a good idea. But rather having a dictionary I would prefer a python template file which contains all the cases. The dictionary/JSON can easily become quite complex when you start to categorise the test cases or you want to test failures with different exceptions etc...

Originally posted by @fekad in #66 (comment)

Missing support for timestamps/datetime in grammar

The grammar is currently missing support for timestamps (or datetime.datetime in terms of Python types).

The relevant section in the spec may be found here.

Specifically we need to recognize timestamps as values being of the form specified by RFC 3339 Internet Date/Time Format and then turn them into datetime.datetime objects if they are OK, otherwise, the implementation should return a 400 Bad Request.

Implement relationships in server

Relationships should be implemented in the server.

The generic example involves a structure with a related reference.
These references may also then be provided in the top-level included field.

setuptools package with server as "extra"

Great work on the optimade tools.

Unfortunately, the server implementation brings a lot of dependencies (including Python 3.7?). This way, I cannot use the package out of the box (i.e. git repo) and have to either clone/copy code, or modify the setup, etc.

Would be great, if this had more flexibility and we could use an additional "extra" (similar to dev, e.g. pip install optimade[server]) to make it more modular.

If you agree, I could try to find the time and prepare pull request: #63

Commented-out validator

The issue is class-inheritance.
This validator is run for sub-classes as well, as was intended, but it doesn't register and recognize the instance of the sub-class as that: An instance of the sub-class. Instead it thinks it's an instance of the parent class and fails.
In the pydantic docs it's writen that this can be avoided by passing the check_fields=False to the validator. But this is for pydantic v1, and didn't seem to work for me when I tested it here.
So I have commented it out, since it should be able to work for pydantic v1.

I don't know if this makes this PR blocked until we have upgraded or not, but it definitely not desireable to have a commented out model validator.

Originally posted by @CasperWA in #103

This is most optimally fixed in a PR that moves this repo to pydantic v1.

List properties and HAS _ operators missing

This is known, but just so we have an issue for it, we are still missing this functionality. A discussion was started in @fekad's PR.

Required in the spec:

  • HAS ANY
  • HAS ALL

Optional:

  • HAS ONLY
  • Search over correlated data e.g. list1:list2:... HAS val1:val2:...

Create "special" index meta-database server

Since this is something all providers, who want to join the providers.json in the OPTiMaDe specification repository need to have, I suggest we create a special instance of the server that only serves the appropriate endpoints (/links and /info), with a JSON file that can be altered for each implementation provider.

Essentially, it will utilize the enhancements introduced by PRs #95 and #99 to serve specific endpoints and load a JSON file similarly to how we currently load test entries.

This server may be started with a separate bash script or by editing the script so that one can pass a desire to switch to a different FastAPI application.

Implement LENGTH in query

It is easy to match ("=") the size of an array in MongoDB but it is not obvious to use the size of an array in other comparisons.
As far as I can see there are two options:

  • we can use $where which is slow,
  • we can store the size of the arrays explicitly in the database. To avoid any collision we could use a postfix like: _SIZE. This should unique because all the properties are lowercase.

server.jsonapi has no patternProperties

In the current version of pydanitc patternProperties can only be added inside sub-elements of properties. If that is fixed then remove items from optimade.server.models.jsonapi.Attributes and optimade.server.models.jsonapi.Realationships and make it match that new formalism.

Somewhere in the creation of the openapi.json file the patternProperties is lost (likely something is using an old version of pydantic that converts a Dict object to object if the key is not a string).

PyPI release checklist

Hi all, we should prepare a PyPI release once we're up to date with v0.10.0 of the spec, as the paper approaches a final draft.

This issue is intended to track packaging changes before the release, and NOT missing features/functionality of the release, which we can track at #29.

  • Currently it looks like @dwinston is the maintainer on PyPI, so we might need to get that changed (not sure if Donny is still following here, so we should reach out to him)?
  • Should we align PyPI major.minor version numbers with the specification? A third number can be free to track hotfixes to both the server and any changes that reflect minor fixes to the spec.
  • We should decide which versions of dependencies to lock in, the important ones being Lark, FastAPI and pydantic.
  • Should we switch dependency handling to pipenv? #37

disable serving API under /v0.10 and /v0.10.0 by default?

Currently, optimade-python-tools serves the same API under three separate base urls:

  • /optimade/
  • /optimade/vMAJ.MIN
  • /optimade/vMAJ.MIN.PAT

Besides bloating the openapi.json file and the corresponding swagger documentation, I would argue this also creates an expectation on the client side that the API will remain available under these base urls.
However - if I understand correctly - in the current implementation of the optimade-python-tools this is not foreseen. E.g. if we update the models for spec v0.10.1, then the /optimade/v0.10.0 base url will be gone.

To me this suggests that the default behavior of the server should be to serve only under /optimade, while making it easy for developers to replicate the API under additional base urls if they wish to do so.

Add more tests

We should add tests for:

  • The error handlers. Testing ErrorResponse and all of the different Exception handlers.
  • The validator. Run client and run validator. Test Client in validator, etc.
    • the CLI
    • validating mandatory filter examples from spec (done in #213)
    • validating optional filter examples from spec
  • response_fields is not tested.
  • sort is not tested.
    • May be implemented by #390
  • Parse JSON config-file.
    • Implemented by #137
  • Field validation edge-cases, making sure the regex for the query parameters catch all
  • Landing page.

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.