An API for the Marble platform.
- MongoDB server
Marble API uses Magpie for authentication.
Authentication is enforced for the following routes:
- admin routes:
/vX/admin/(whereXis a version number) - user routes:
/vX/users/Y/(whereXis a version number andYis a user name)
Only users who belong to the group named "administrators" in Magpie will have access to
the admin routes. Only users whose Magpie user name matches the Y in user routes will
have access to the given user route.
Authn/z can be configured with the following environment variables:
MARBLE_API_MAGPIE_AUTH_ENABLED- default:
True - type: boolean
- set to
Falseto disable authentication entirely (this is not recommended in a production environment)
- default:
MARBLE_API_MAGPIE_URL- default:
None - type: string (URL format)
- set to the URL for the Magpie instance used to authenticate users
- default:
MARBLE_API_MAGPIE_ADMIN_GROUP- default:
administrators - type: string
- change this if you want a different Magpie group to be have access to the admin routes
- default:
When integrating Marble API with the birdhouse platform we recommend enabling it with the Marble API component. This sets default environment variables that will work with most birdhouse deployments.
To start a development server:
python3 -m pip install .[dev]
MARBLE_API_MONGODB_URI="mongodb://localhost:27017" fastapi dev marble_apiThis assumes that you have a mongodb service running at mongodb://localhost:27017.
Or to start developing using docker:
docker compose -f docker-compose.dev.yml upThis will start a dedicated mongodb container for use with your app. Note that this will track changes you make dynamically so you don't have to restart the container if you make changes to the source code while the container is running.
We welcome any contributions to this code. To submit suggested changes, please do the following:
- create a new feature branch off of
main - update the code, write/update tests, write/update documentation
- submit a pull request targetting the
mainbranch
This codebase uses the ruff formatter and linter to enforce style policies.
To check that your changes conform to these policies please run:
ruff format
ruff checkYou can also set up pre-commit hooks that will run these checks before you create any commit in this repo:
pre-commit installMarble API is a versioned REST API. Backwards compatible changes can be made to existing versions. If you wish to introduce backwards incompatible changes, you must create a new version.
To create a new version:
- create a new directory under
app/versionswith the name of the next version (eg: v2, v3, etc.) - create a new
fastapi.APIRouterrouter in that directory and add any routes, models, etc. - the new router should have a prefix of the form
vXwhereXis the version number (eg:/v2,/v3, etc.) - in
app/main.pyimport the app from the new version and add it to the app with.include_router.
To run tests:
python3 -m pip install .[dev]
MARBLE_API_MONGODB_URI="mongodb://localhost:27017" pytest ./testThis assumes that you have a mongodb service running at mongodb://localhost:27017.
Alternatively you can run start up the development stack with docker compose and then run tests in the docker container:
docker compose -f docker-compose.dev.yml up -d
docker compose exec marble_api pytest ./test