Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Ariadne is a Python library for implementing GraphQL servers.
Documentation is available here.
.graphql
, .gql
, and .graphqls
files.camelCase
and snake_case
, and a @convert_kwargs_to_snake_case
function decorator for converting camelCase
kwargs to snake_case
.gql()
helper function. Also provides colorization if Apollo GraphQL extension is installed.Apollo Federation
.Ariadne can be installed with pip:
pip install ariadne
Ariadne requires Python 3.7 or higher.
The following example creates an API defining Person
type and single query field people
returning a list of two persons. It also starts a local dev server with GraphQL Playground available on the http://127.0.0.1:8000
address.
Start by installing uvicorn, an ASGI server we will use to serve the API:
pip install uvicorn
Then create an example.py
file for your example application:
from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
# Define types using Schema Definition Language (https://graphql.org/learn/schema/)
# Wrapping string in gql function provides validation and better error traceback
type_defs = gql("""
type Query {
people: [Person!]!
}
type Person {
firstName: String
lastName: String
age: Int
fullName: String
}
""")
# Map resolver functions to Query fields using QueryType
query = QueryType()
# Resolvers are simple python functions
@query.field("people")
def resolve_people(*_):
return [
{"firstName": "John", "lastName": "Doe", "age": 21},
{"firstName": "Bob", "lastName": "Boberson", "age": 24},
]
# Map resolver functions to custom type fields using ObjectType
person = ObjectType("Person")
@person.field("fullName")
def resolve_person_fullname(person, *_):
return "%s %s" % (person["firstName"], person["lastName"])
# Create executable GraphQL schema
schema = make_executable_schema(type_defs, query, person)
# Create an ASGI app using the schema, running in debug mode
app = GraphQL(schema, debug=True)
Finally run the server:
uvicorn example:app
For more guides and examples, please see the documentation.
We are welcoming contributions to Ariadne! If you've found a bug or issue, feel free to use GitHub issues. If you have any questions or feedback, don't hesitate to catch us on GitHub discussions.
For guidance and instructions, please see CONTRIBUTING.md.
Website and the docs have their own GitHub repository: mirumee/ariadne-website
Also make sure you follow @AriadneGraphQL on Twitter for latest updates, news and random musings!
Crafted with ❤️ by Mirumee Software hello@mirumee.com
FAQs
Ariadne is a Python library for implementing GraphQL servers.
We found that ariadne demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.