Introducing Tartiflette: An Open Source GraphQL Implementation for Python 3.6+

    Friends, on the eve of the May holidays, we decided not to bombard you with complicated technical articles, so we found quite interesting, and most importantly, easy to read material, the translation of which we are happy to share with you. This material we want to coincide with the launch of the course "Web-developer in Python . "

    The original can be found here .



    The acquisition of Vivendi dailymotion three years ago was a turning point for our organization. This allowed us to rethink the vector of our work, to rethink our work itself from beginning to end. We used this opportunity to evaluate dailymotion in general, to rethink our infrastructure and, more importantly, the architecture of our products.

    In the end, the self-analysis confirmed what we already knew: we wanted to geographically distribute our platform and develop APIs , mobile and TV applications. This marked the abandonment of the current monolithic structure and the adoption of an API-oriented approach. This article describes the path we followed.

    Criteria and concept checks

    We started the project by defining API criteria, which ultimately narrowed to four points:

    • Providing good DX (developer experience), easy use and implementation;
    • The cultivation of a solid and growing community , one that would allow the aggregation and use of widespread technology;
    • Behavior similar to the gateway in terms of software architecture , aimed at simplifying the transformation of our system integration from monolith to SOA (service-oriented architecture);
    • The ability to implement API management tools, namely API management, documentation and data access.

    Next, we selected several API models and tested several concepts to understand their appropriateness:

    • Rest API with Swagger
    • GraphQL API with Graphene
    • API with Falcor



    After rigorous testing, we found that GraphQL and its Graphene implementations met our criteria best when compared to other models. This allowed our front-end developers to more easily use our API, and at the same time simplify its use in client applications (for example, React JS and Apollo Client). In our architecture, GraphQL also proved to be simpler and more efficient as a pattern gateway. In the end, we finally decided to move on with GraphQL and Graphene.

    The Way to Production

    In April 2017, after an intensive six-month development, we went into production with our API. By the summer, we switched all dailymotion products (web, mobile and TV) to our GraphQL API.



    When we chose GraphQL three years ago, it was still in beta and did not reach the popularity it has today. We were the first major players in this arena and this made our internal reconstruction even more enjoyable.

    The birth of Tartiflette

    In the first months of 2018, after more than six months of using Graphene, we decided to take a step further and write our own GraphQL engine. This allowed us to implement some requirements that were not met by Graphene. We have developed criteria for our own engine. He must:

    • Provide the best thinking DX for Python developers;
    • Use SDL (Schema Definition Language);
    • Use asyncio as a standalone executing engine;

    After almost a year of development and many weeks of testing our infrastructure (on average more than 100 million calls were processed per day), we are proud to offer the GraphQL community our own open-source Tartiflette engine.

    Tartiflette DNA Tartiflette

    is a GraphQL Server implementation built on Python 3.6+.
    The GraphQL schema is described using the new Schema Definition Language (SDL) ;
    Performance is a key element of our work and this is reflected in Tartiflette ;
    Built with Zen of Python in mind . Not overly complicated.

    Hello world on tartiflette



    import asyncio
    from tartiflette import Engine, Resolver
    @Resolver("Query.hello")asyncdefresolver_hello(parent, args, ctx, info):return"hello " + args["name"]
    asyncdefrun():
        ttftt = Engine("""
        type Query {
            hello(name: String): String
        }
        """)
        result = await ttftt.execute(
            query='query { hello(name: "Chuck") }'
        )
        print(result)
        # {'data': {'hello': 'hello Chuck'}}if __name__ == "__main__":
        loop = asyncio.get_event_loop()
        loop.run_until_complete(run())
    

    You can find out about the new functionality in the manual on tartiflette.io .

    What will happen next with Tartiflette?

    The open source Tartiflette is just the first step. Here are a few ideas and plans for the future for the development of Tartiflette:

    • "Polishing" documentation for users and the community;
    • Providing more examples and expanding use cases to inspire you to experiment with the capabilities of Tartiflette ;
    • Increased productivity , mainly at the level of the execution engine.

    And we need you too!



    You can use our project for almost any purpose and help us in the development of Tartiflette! Please check it for durability, do not hesitate to look for errors or contradictions in the code and maintain feedback to improve the product. We truly believe that Tartiflette will get better with close collaboration with the community.

    How to contribute to the project?

    Tartiflette on Github ;
    Read the documentation at tartiflette.io ;
    Send feedback and suggestions to Slack ;
    Join the community on Twitter .

    Also popular now: