Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python GraphQL libraries build GraphQL APIs that let clients ask for exactly the fields they need in one request. A code-first library generates the schema from Python classes rather than from a schema written in the GraphQL language. These libraries let web and mobile apps fetch nested data from a backend in a single round trip.
Popularity
graphql-core has the most monthly downloads in this comparison, at 79.1M.
def __init__(
self,
request: Union[DocumentNode, "GraphQLRequest", str],
*,
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
extensions: Optional[Dict[str, Any]] = None,
):
"""Initialize a GraphQL request.
:param request: GraphQL request as DocumentNode object or as a string.
If string, it will be converted to DocumentNode.
:param variable_values: Dictionary of input parameters (Default: None).
:param operation_name: Name of the operation that shall be executed.
Only required in multi-operation documents (Default: None).
:param extensions: Dictionary of protocol extensions (Default: None).
This is passed as the top-level "extensions" key in the request
payload, as defined in the GraphQL over HTTP spec.
:return: a :class:`GraphQLRequest <gql.GraphQLRequest>`
which can be later executed or subscribed by a
:class:`Client <gql.client.Client>`, by an
:class:`async session <gql.client.AsyncClientSession>` or by a
:class:`sync session <gql.client.SyncClientSession>`
:raises graphql.error.GraphQLError: if a syntax error is encountered.
"""
if isinstance(request, str):
source = Source(request, "GraphQL request")
self.document = parse(source)
elif isinstance(request, DocumentNode):
self.document = request
elif not isinstance(request, GraphQLRequest):
raise TypeError(f"Unexpected type for GraphQLRequest: {type(request)}")
if isinstance(request, GraphQLRequest):
self.document = request.document
if variable_values is None:
variable_values = request.variable_values
if operation_name is None:
operation_name = request.operation_name
if extensions is None:
extensions = request.extensions
self.variable_values: Optional[Dict[str, Any]] = variable_values
self.operation_name: Optional[str] = operation_name
self.extensions: Optional[Dict[str, Any]] = extensions
Graphene
Builds GraphQL API schemas using Python classes.
Downloads / mo
32.0M
Stars
8.2K
Last release
3.4.3
License
MIT
Strengths
Defines schemas with Python classes.Describe API fields in Python instead of writing SDL separately.
Includes Relay support.Build Relay-compatible APIs with the bundled Relay helpers.
Limitations
Field names change to camelCase.Disable auto_camelcase to preserve Python field names in the schema.
GraphQL-core versions are constrained.Keep GraphQL-core within the dependency range required by Graphene.
def get_possible_type_definitions(
gql_type: StrawberryObjectDefinition | StrawberryType | type,
) -> Generator[StrawberryObjectDefinition]:
"""Resolve all possible type definitions for gql_type.
Args:
---- gql_type:
The type to retrieve possibilities from.
Yields:
------ All possibilities for the type
"""
if isinstance(gql_type, StrawberryObjectDefinition):
yield gql_type
return
for t in get_possible_types(gql_type):
if isinstance(t, StrawberryObjectDefinition):
yield t
elif has_object_definition(t):
yield t.__strawberry_definition__
Ariadne
Builds GraphQL servers around schemas written in SDL.
Downloads / mo
2.1M
Stars
2.3K
Last release
1.1.1
License
BSD-3-Clause
Strengths
Starts with SDL schemas.Write the public schema first, then attach Python resolver functions.
Supports async and sync resolvers.Use asynchronous or synchronous Python resolver functions.
Limitations
Subscriptions need an ASGI server.Use ASGI for WebSocket or server-sent event subscriptions.
def __init__(
self, connection: type[Connection], *args: Any, **kwargs: Any
) -> None:
if self.filter_arg not in kwargs:
model = connection._meta.node._meta.model
with suppress(KeyError):
kwargs[self.filter_arg] = self.filters[model]
super().__init__(connection, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
config = get_config()
# Enforce GRAPHQL_ENABLED if not config.GRAPHQL_ENABLED:
return HttpResponseNotFound("The GraphQL API is not enabled.")
# Attempt to authenticate the user using a DRF token, if provided if not request.user.is_authenticated:
authenticator = TokenAuthentication()
try:
auth_info = authenticator.authenticate(request)
if auth_info is not None:
request.user = auth_info[0] # User object
except AuthenticationFailed as exc:
return HttpResponseForbidden(exc.detail)
# Enforce LOGIN_REQUIRED if settings.LOGIN_REQUIRED and not request.user.is_authenticated:
# If this is a human user, send a redirect to the login page if self.request_wants_html(request):
return redirect_to_login(reverse('graphql'))
return HttpResponseForbidden("No credentials provided.")
return super().dispatch(request, *args, **kwargs)
FAQ
Strawberry suits new APIs built from dataclasses and type annotations. Graphene suits code-first APIs with existing Django or SQLAlchemy integrations. Ariadne suits teams that write the schema first in SDL.
Define a schema with Strawberry types, Graphene classes, or an SDL string for Ariadne, then bind resolvers to its fields. Each framework serves the schema through an ASGI or WSGI integration.
Graphene Django generates Graphene types from Django models and serves them through a Django GraphQL view.
graphql-core is the low-level GraphQL type system, parser, validator, and executor for Python. Higher-level frameworks such as Graphene and Strawberry run on top of it.
For coding agents
Found your GraphQL library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.