GithubHelp home page GithubHelp logo

line / centraldogma-python Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 10.0 2.85 MB

Python client library for Central Dogma

Home Page: https://line.github.io/centraldogma-python/

License: Apache License 2.0

Python 100.00%

centraldogma-python's People

Contributors

darjeeling avatar hexoul avatar ikhoon avatar jrhee17 avatar

Stargazers

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

Watchers

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

centraldogma-python's Issues

Use `Query` type instead of `str`

#14 introduced Query type. The existing APIs that use a string as a query expression need to be updated such as.

path_pattern: Optional[str],

class Query(Generic[T]):
@staticmethod
def identity(path: str) -> Query[str]:
return Query(path=path, query_type=QueryType.IDENTITY, expressions=[])
@staticmethod
def text(path: str) -> Query[str]:
return Query(path=path, query_type=QueryType.IDENTITY_TEXT, expressions=[])
@staticmethod
def json(path: str) -> Query[Any]:
return Query(path=path, query_type=QueryType.IDENTITY_JSON, expressions=[])
@staticmethod
def json_path(path: str, json_paths: List[str]) -> Query[Any]:
return Query(path=path, query_type=QueryType.JSON_PATH, expressions=json_paths)

Raise proper exceptions rather then return optional values

I found some APIs whose return type should be Optional type. So the return type needs to be wrapped with Optional.

def create(self, project_name: str, name: str) -> Repository:
resp = self.client.request(
"post", f"/projects/{project_name}/repos", json={"name": name}
)
if resp.status_code != HTTPStatus.CREATED:
return None
return Repository.from_json(json.dumps(resp.json()))

While I tried to use Optional[Repository], I thought that it would be better to raise a specific exception such as ProjectExistsException
rather than None. Because the meaning of None is pretty implicit.
https://github.com/line/centraldogma/blob/b167d594af5abc06af30d7d6d7d8b68b320861d8/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/ArmeriaCentralDogma.java#L119-L132
We can see exception of error response for decoding to proper exceptions.
https://github.com/line/centraldogma/blob/b167d594af5abc06af30d7d6d7d8b68b320861d8/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/ArmeriaCentralDogma.java#L1159-L1163

Support HTTP/2

requests only supports HTTP/1 and is almost archived not to add new features. We need to consider other packages to support both HTTP/1 and HTTP/2. httpx is one of powerful candidates.

update README and documentation to use http2

I installed package and used example code from README.md.

but I got import error, as I read the code it's default value. so I think it should be documented well

ImportError: Using http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.

I think we need to update this on README.md and documentation

Publish to PyPI

Installing this client with pip install is very useful.
Is there any obstacle to publish this client to PyPI?

Support asyncio

Central Dogma provides a watch API with a long connection. It would be inefficient to use a thread for watching files.
I think we can use Event loop and Coroutines with asyncio for better performance and fewer resources.

Make proper exceptions when the client gets error response

Related #1 (comment)
We need to make proper exceptions when the response status is not the expected one.
Also, we might want to provide fine-grained exceptions as we do upstream.
For example, we could split NotFoundException to RevisionNotFoundException, ProjectNotFoundException and RepositoryNotFoundException.

Use dedicated `Revision` type instead of primitive int

Currently, a revision is represented as an int.

revision: Optional[int] = None,

It would be nice to use a dedicated type introduced in #14
class Revision:
def __init__(self, major):
self.major = major
@staticmethod
def init() -> Revision:
return _INIT
@staticmethod
def head() -> Revision:
return _HEAD
_INIT = Revision(1)
_HEAD = Revision(-1)

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.