GithubHelp home page GithubHelp logo

erewok / servant-py Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 6.0 47 KB

Servant client generators for the Python language

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%
haskell haskell-library python servant servant-client

servant-py's People

Contributors

erewok avatar exarkun avatar mostawesomedude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

servant-py's Issues

Don't allow function parameters that overload keywords

We have a capture in one of our test API endpoints where the variable is named id. This is created as a function parameter and passed into the client function.

Ideally, we wouldn't overload any Python keywords, such as id, because it's gross and poor form.

Possibly check for membership in a list of keywords and rename if so.

Add asyncio option

With the new Async stuff in Python, we should be able to emit client code in servant-py that will utilize httpx and asyncio. We can add it here as a different generator.

`toPyDict` doesn't separate multiple arguments

It'll build a dict like this:

test :: [Text] -> Text
test = ["one", "two", "three"]
let result = toPyDict test
result
\"{\"one\":one\"two\":two\"three\":three\"}

We forgot to build a complete structure out of it. Probably pass an offset parameter to fix this so it nicely indents members of the resulting dict.

Rewrite Output Functions for better naming and organization

So, I have been thinking about this library and I think I'd like to make the output functions a little more usable. I had the following ideas:

  1. Build Class definitions for URLs where the route is totally common but there are different methods, something like this:
class SomeRoute:
    def __init__(self):
      self.url = "some/url/{param1}/etc"
      pass
    def get(self, param1):
      return requests.get(self.url.format(param1=param1))
   def post(self, param1, payload):
      etc.
  1. Instead of (or in addition to) the above, we could also separate functions into modules so that you can do something like dotted function call:
import some_url_client

some_url_client.get()

The default way of naming functions creates really long functions, so we need something consistent that also creates an API that's not ultimately painful to use.

I'll experiment and try to see what'll work best.

Add Return information to docstring.

Docstring now doesn't contain a returns: section, which would make it a little more official.

Ideally, we'd include more information about the types of things that go into the functions as arguments, including the data payload, etc. That may involve more knowledge about Python than this library currently pretends to.

In addition, we should be able to include some information in the returns section about the kind of object likely to get returned.

Add tests

They are sorely needed.

It should be fun to do.

APIs with captures are rendered to syntactically invalid Python

Part of the test suite which is commented out fails now if tweaked slightly to fix a type error:

    it "should build urls properly with / separator" $ do
      let pyUrl = makePyUrl customOptions (UnTypedPythonRequest req) " "
      pyUrl `shouldBe` "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\""
                       <> withFormattedCaptures " " pathParts

Failures:

  test/Servant/PY/InternalSpec.hs:131:7: 
  1) Servant.PY.Internal.Servant.PY.Internal.Internal, functions that operate on Req objects, should build urls properly with / separator
       expected: "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\".format(\n id=parse.quote(str(id)),\n Name=parse.quote(str(Name)),\n hungrig=parse.quote(str(hungrig)))"
        but got: "\"urlForRequesting:9000/login-with-path-var-and-header/{id}/{Name}/{hungrig}\".format(\n id=parse.quote(str(id)),\n Name=parse.quote(str(Name)),\n hungrig=parse.quote(str(hungrig)))\""

use python3 type annotations

This library contains a confusingly named withTypes Python generator options, but we're not using Python3 type annotations, when it seems like we should be.

Add a new style of generating Python output using Python3 type annotations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.