Skip to main content

apiX - The Python framework to create MongoDB-backed applications with GraphQL API web interface.

Project description


Documentation: https://apix.org (in progress)

Source Code: https://github.com/ApixOrg/apix


apiX is a framework to create MongoDB-backed applications with a GraphQL API web interface. apiX drastically simplifies the linkage between the backend and the web interface. apiX enables you to build applications in a beautiful pythonic way without dealing with technical libraries, such as, pymongo for MongoDB operations and graphql-core for the GraphQL API.

Installation

apiX is available on PyPI and can be installed with pip.

pip install apix

You can also directly install the latest version from Github.

pip install git+https:://github.com/ApixOrg/apix.git

Why use MongoDB and GraphQL?

Description MongoDB is a schemaless database that stores arbitrary JSON objects (so called "Documents"). GraphQL is a flexible query language for APIs that allows you to specify exactly the fields which you want to request.
Advantages 1. Create document collections on-the-fly.
2. Documents can be nested and contain arrays.
3. Powerful data platform in the cloud available.
1. Reduce the amount of data transmitted.
2. The requests are strictly type-safe.
3. Multiple resources can be collected in a single request.
Article Why use MongoDB? Why use GraphQL?

Example App

Make sure that you have apiX and uvicorn installed. Before you run the python code, replace the CONNECTION_STRING placeholder with the connection string to your MongoDB instance.

import uvicorn
from apix import *


# Connection details of your MongoDB instance
Database = ApixDatabase(
    host='CONNECTION_STRING',
    name='demo',
)


# User model definition
User = ApixModel(
    name='user',
    attributes=[
        ApixStringAttribute('name'),
        ApixIntegerAttribute('age'),
    ],
)


# Function to create a user
def create_user(user: User) -> User:
    Database(User).insert_one(user)
    return user


# Function to find a user by name
def find_user_by_name(name: str) -> User:
    return Database(User).find_one(User.Name.Equal(name))


# Create the app
app = ApixApp(
    resolvers=[
        ApixMutationResolver(create_user),
        ApixQueryResolver(find_user_by_name),
    ],
)

if __name__ == '__main__':
    uvicorn.run(
        app=app,
        host='localhost',
        port=8080,
    )

Once your app is running, the GraphQL API web interface is available at http://localhost:8080/graphql. Now open your favorite web client (such as Insomnia or Postman) and create a user with the following request.

mutation {
    createUser(
        user: {
            name: "Dan"
            age: 30
        }
    ) {
        id
        name
        age
    }
}

To search for the user by name you can use the request below.

query {
    findUserByName(
        name: "Dan"
    ) {
        id
        name
        age
    }
}

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

apix_core-0.0.4.tar.gz (24.5 kB view hashes)

Uploaded Source

Built Distribution

apix_core-0.0.4-py3-none-any.whl (34.8 kB view hashes)

Uploaded Python 3

Supported by

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