https://github.com/bluebrain/virtual-lab-api

Source code for the virtual labs RESTful API

https://github.com/bluebrain/virtual-lab-api

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.0%) to scientific vocabulary

Keywords

neuroscience restful-api
Last synced: 5 months ago · JSON representation

Repository

Source code for the virtual labs RESTful API

Basic Info
Statistics
  • Stars: 1
  • Watchers: 5
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Archived
Topics
neuroscience restful-api
Created almost 2 years ago · Last pushed 12 months ago
Metadata Files
Readme Contributing License Authors

README.md

[!WARNING] The Blue Brain Project concluded in December 2024, so development has ceased under the BlueBrain GitHub organization. Future development will take place at: https://github.com/openbraininstitute/virtual-lab-api

Virtual Labs API

This is the repository for the REST api that is used to manage virtual labs and their projects, primarily by the core-web-app.

Dependencies

Make sure you have the following dependencies installed:

  • python (version 3.12)
  • poetry (version >=1.5.1)
  • docker - Add the docker group to your user to enable running docker without sudo. This can be done by running sudo usermod -a -G <your username>
  • jq
  • Stripe API key (STRIPE_SECRET_KEY test key and STRIPE_DEVICE_NAME=dev in ./.env.local)

Development

  1. Install the dependencies

bash poetry install 2. Start dev environment

bash make init 3. Run db migrations (this also initializes the database)

make init-db

This should start the server on port 8000 (http://127.0.0.1:8000) The docs will be available at http://127.0.0.1:8000/docs#/

Retrieving tokens for test users

The token for user test (only user right now that can create virtual labs) is already copied to your clipboard when you run make init. Tokens for user test, test-1, or test-2 can also be retrieved using the script get_user_token.sh. It echoes the token to the stdout as well as copies it to your clipboard.

```bash ./getusertoken.sh

Now you will be prompted to enter a username. Valid usernames are test, test-1, or test-2. Example:

Enter username (test, test-1 or test-2) -rtest-1 Access token: ```

Accessing local (or test) keycloak UI

Add keycloak as host for address 127.0.0.1 in /etc/host file

bash echo "127.0.0.1 keycloak" | sudo tee -a /etc/hosts # This adds a line "127.0.0.1 keycloak" to /etc/hosts

Now navigating to http://localhost:9090 or http://keycloak:9090 should load the keycloak web interface

Generating db migrations

The version numbers are stored in alembic/versions. Alembic can be used to autogenerate migration scripts based on schema changes like so:

poetry run alembic revision --autogenerate -m '<A descriptive message>'

Note that these migration scripts should be reviewed carefully. Also, not all schema changes can be autogerated. Details about which schema changes need scripts to be written manually are here.

Migration can be run like so:

poetry run alembic upgrade head

To check if migration is needed (same as above, alembic cannot check all schema changes):

make check-db-schema

Testing

Tests can be run using the following command:

make test

Test Billing endpoints

The following section explains how to test attaching a payment method to a customer using Stripe's Setup Intents. This operation primarily involves frontend interactions to verify and confirm the Setup Intent. Therefore, it's crucial to conduct this part of the API testing manually.

Prerequisites:

  1. Stripe CLI: Installation of Stripe CLI is recommended for facilitating local testing and event simulation. It can be downloaded from the Stripe CLI documentation page.

Steps to Test:

  1. Create a Setup Intent: Initially, create a Setup Intent to prepare for attaching a payment method to a customer by using /virtual-labs/{virtual_lab_id}/billing/setup-intent endpoint.
  2. Confirm the Setup Intent: Manually pass the Setup Intent ID to the confirm method to simulate the user confirming their payment details (in the frontend this op is using stripe.setupConfirm()). This action triggers Stripe to attach the specified test payment method to the Setup Intent.

Alternatively, if you prefer not to use Stripe CLI, you can execute a POST request directly to Stripe's API to perform these actions. However, using Stripe CLI provides a more integrated and straightforward testing workflow.

For further details on working with Setup Intents and managing payment methods, refer to the Stripe API documentation on Setup Intents.

sh stripe setup_intents confirm seti_1PFtBwFjhkSGAqrAUHCvTAAA \ --payment-method=pm_card_visa

IDE Setup

VS Code

  1. Make sure that VSCode is picking up the right python version. This should look like ~/.cache/pypoetry/virtualenvs/virtual-labs[uuid]...
  2. Recommended extensions:
    • Ruff (extension_id - charliermarsh.ruff)
    • MyPy Type Checker (extension_id: ms-python.mypy-type-checker)

Contributing

To create an MR and push code to it, you will need to setup git-hooks only the first time you push code to the repo.

  1. Install git hooks to enable pre-push checks

poetry run pre-commit install

This will setup a git hook (pre-push) that is configured to run the following checks.

  • Formatting (using ruff)
  • Linting (using ruff)

Funding & Acknowledgment

The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government's ETH Board of the Swiss Federal Institutes of Technology.

Copyright © 2024 Blue Brain Project/EPFL

Owner

  • Name: The Blue Brain Project
  • Login: BlueBrain
  • Kind: organization
  • Email: bbp.opensource@epfl.ch
  • Location: Geneva, Switzerland

Open Source Software produced and used by the Blue Brain Project

GitHub Events

Total
  • Watch event: 1
  • Delete event: 4
  • Issue comment event: 1
  • Push event: 6
  • Pull request review event: 4
  • Pull request event: 7
  • Fork event: 1
  • Create event: 3
Last Year
  • Watch event: 1
  • Delete event: 4
  • Issue comment event: 1
  • Push event: 6
  • Pull request review event: 4
  • Pull request event: 7
  • Fork event: 1
  • Create event: 3

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 2
  • Total pull requests: 181
  • Average time to close issues: 1 day
  • Average time to close pull requests: 3 days
  • Total issue authors: 1
  • Total pull request authors: 4
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.33
  • Merged pull requests: 169
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 181
  • Average time to close issues: 1 day
  • Average time to close pull requests: 3 days
  • Issue authors: 1
  • Pull request authors: 4
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.33
  • Merged pull requests: 169
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • xari (1)
  • pgetta (1)
Pull Request Authors
  • Dinika (74)
  • bilalesi (36)
  • pgetta (4)
  • genric (3)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/main-branch-workflow.yml actions
  • actions/checkout v4 composite
  • docker/login-action v3 composite
.github/workflows/pull-request-workflow.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
Dockerfile docker
  • python 3.12-bookworm build
  • python 3.12-slim-bookworm build
env-prep/docker-compose-dev.yml docker
  • axllent/mailpit latest
  • bluebrain/blazegraph-nexus 2.1.6-RC
  • bluebrain/nexus-delta latest
  • docker.elastic.co/elasticsearch/elasticsearch 8.12.1
  • library/postgres 15.6
  • postgres latest
  • quay.io/keycloak/keycloak 24.0
  • stripe/stripe-cli latest
poetry.lock pypi
  • aiosmtplib 2.0.2
  • alembic 1.13.1
  • annotated-types 0.6.0
  • anyio 4.3.0
  • asyncpg 0.29.0
  • asyncpg-stubs 0.29.1
  • blinker 1.7.0
  • certifi 2024.2.2
  • cffi 1.16.0
  • cfgv 3.4.0
  • charset-normalizer 3.3.2
  • click 8.1.7
  • colorama 0.4.6
  • cryptography 42.0.5
  • datetime 5.5
  • deprecation 2.1.0
  • distlib 0.3.8
  • dnspython 2.6.1
  • email-validator 2.1.1
  • fastapi 0.110.1
  • fastapi-mail 1.4.1
  • filelock 3.13.4
  • greenlet 3.0.3
  • h11 0.14.0
  • httpcore 1.0.5
  • httptools 0.6.1
  • httpx 0.27.0
  • identify 2.5.35
  • idna 3.7
  • iniconfig 2.0.0
  • itsdangerous 2.1.2
  • jinja2 3.1.3
  • jwcrypto 1.5.6
  • loguru 0.7.2
  • mako 1.3.3
  • markupsafe 2.1.5
  • mypy 1.9.0
  • mypy-extensions 1.0.0
  • nodeenv 1.8.0
  • orjson 3.10.1
  • packaging 24.0
  • platformdirs 4.2.0
  • pluggy 1.4.0
  • pre-commit 3.7.0
  • psycopg2-binary 2.9.9
  • pycparser 2.22
  • pydantic 2.7.0
  • pydantic-core 2.18.1
  • pydantic-extra-types 2.6.0
  • pydantic-settings 2.2.1
  • pyjwt 2.8.0
  • pytest 8.1.1
  • pytest-asyncio 0.21.1
  • python-dotenv 1.0.1
  • python-keycloak 3.12.0
  • python-multipart 0.0.9
  • pytz 2024.1
  • pyyaml 6.0.1
  • requests 2.31.0
  • requests-toolbelt 1.0.0
  • ruff 0.2.2
  • setuptools 69.5.1
  • sniffio 1.3.1
  • sqlalchemy 2.0.29
  • starlette 0.37.2
  • stripe 9.6.0
  • types-requests 2.31.0.20240406
  • typing-extensions 4.11.0
  • ujson 5.9.0
  • urllib3 2.2.1
  • uuid 1.30
  • uvicorn 0.27.1
  • uvloop 0.19.0
  • virtualenv 20.25.1
  • watchfiles 0.21.0
  • websockets 12.0
  • win32-setctime 1.1.0
  • zope-interface 6.3
pyproject.toml pypi
  • mypy ^1.8.0 develop
  • pre-commit ^3.6.2 develop
  • pytest ^8.0.2 develop
  • pytest-asyncio 0.21.1 develop
  • python-dotenv ^1.0.1 develop
  • requests ^2.31.0 develop
  • ruff ^0.2.2 develop
  • types-requests ^2.31.0.20240311 develop
  • alembic ^1.13.1
  • asyncpg ^0.29.0
  • asyncpg-stubs ^0.29.1
  • datetime ^5.4
  • fastapi ^0.110.0
  • fastapi-mail ^1.4.1
  • httpx ^0.27.0
  • loguru ^0.7.2
  • psycopg2-binary ^2.9.9
  • pydantic ^2.6.3
  • pydantic-settings ^2.2.1
  • pyjwt ^2.8.0
  • python ^3.12
  • python-dotenv ^1.0.1
  • python-keycloak ^3.9.1
  • sqlalchemy ^2.0.29
  • stripe ^9.6.0
  • uuid ^1.30
  • uvicorn ^0.27.1
setup.py pypi