Skip to main content

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

Project description


Documentation: https://apix.org

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


apiX is a full-stack framework for backend developlment. apiX integrates all necessary components to create powerful backend applications in Python with just a few lines of code. Use apiX to create with ease -backed applications with a GraphQL API .

Integrated technologies

  • MongoDB: The schemaless and document-oriented database is ideal to effortlessly create powerful applications from scratch.
  • GraphQL: The query language for APIs is perfectly suited to create efficient and well-documented APIs.
  • Google Cloud Storage: The powerful object storage from Google allows you store data of any size and format.

Installation

The apiX library is published on PyPI and can be installed with the following pip command.

pip install apix-core

You can use Uvicorn to run the application. Uvicorn is an ASGI web server implementation for Python. To install apiX together with uvicorn run this pip command.

pip install 'apix-core[uvicorn]'

Documentation

Go to our website apix.org and check out the detailed documentation.

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.app import ApixApp
from apix.attribute import ApixIntegerAttribute, ApixStringAttribute
from apix.database import ApixDatabase
from apix.model import ApixModel
from apix.resolver import ApixMutationResolver, ApixQueryResolver
from apix.scalar import ApixString


# 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: ApixString) -> 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 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.10.tar.gz (25.4 kB view hashes)

Uploaded Source

Built Distribution

apix_core-0.0.10-py3-none-any.whl (36.5 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