Integration between the Bioregistry and Pydantic type annotations.
Project description
Semantic Pydantic
Annotate your data models in Pydantic and APIs in FastAPI with the Bioregistry to make them more FAIR
💪 Getting Started
You can use one of the several extensions to Pydantic and FastAPI's Field
classes.
from pydantic import BaseModel, Field
from semantic_pydantic import SemanticField
class Scholar(BaseModel):
"""A model representing a researcher, who might have several IDs on different services."""
orcid: str = SemanticField(..., prefix="orcid")
name: str = Field(..., example="Charles Tapley Hoyt")
wos: str | None = SemanticField(default=None, prefix="wos.researcher")
dblp: str | None = SemanticField(default=None, prefix="dblp.author")
github: str | None = SemanticField(default=None, prefix="github")
scopus: str | None = SemanticField(default=None, prefix="scopus")
semion: str | None = SemanticField(default=None, prefix="semion")
publons: str | None = SemanticField(default=None, prefix="publons.researcher")
authorea: str | None = SemanticField(default=None, prefix="authorea.author")
Similarly, this can be used in FastAPI.
from fastapi import FastAPI
from semantic_pydantic import SemanticPath
app = FastAPI(title="Semantic Pydantic Demo")
Scholar = ... # defined before
@app.get("/api/orcid/{orcid}", response_model=Scholar)
def get_scholar_from_orcid(orcid: str = SemanticPath(prefix="orcid")):
"""Get xrefs for a researcher in Wikidata, given ORCID identifier."""
... # full implementation in https://github.com/cthoyt/semantic-pydantic
return Scholar(...)
Here's what the Swagger UI looks like, including all the annotations on both the data model and endpoint arguments.
The demo can be run by cloning the repository, installing its requirements, and
running the self-contained demo.py
.
🚀 Installation
The most recent code and data can be installed directly from GitHub with:
pip install git+https://github.com/cthoyt/semantic-pydantic.git
👐 Contributing
Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See CONTRIBUTING.md for more information on getting involved.
👋 Attribution
⚖️ License
The code in this package is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file semantic_pydantic-0.0.1.tar.gz
.
File metadata
- Download URL: semantic_pydantic-0.0.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5230bae4c50ad8270b855b628c230c0b20e16c89e617e4d40824075f7b4eb722 |
|
MD5 | 33dc8f1e7473fefd1e99a17d5712a1e1 |
|
BLAKE2b-256 | 39f7269a1de592d83a4dad5a649182c55e9242854e34ec552b6f88cea89b9348 |
Provenance
File details
Details for the file semantic_pydantic-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: semantic_pydantic-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee10882d5b3848b22c59c05c7ae4172c19324924401defc69948fee13f0547db |
|
MD5 | 1cba6e861326151de5c6f5a56a53f466 |
|
BLAKE2b-256 | b95cd07e1dc9dea60bdf43d8262c71b7376308192899d95afcd19446e9812ae1 |