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
Built Distribution
Hashes for apix_core-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bb294ce3e61d060178f2042931c70e5939cf4edffd37a4e6e1c753a4fc25ca8 |
|
MD5 | 3fccf56cb2471dc2cd066673e7131eac |
|
BLAKE2b-256 | f351d1acd4f7a089c9a2383922cb744f3210d864a915e2314daefdb4c4a5be6a |