先进的库和 API 设计

发布于 2024-11-04 06:12:42 字数 684 浏览 1 评论 0原文

我正在开发一个使用 CMIS 兼容存储作为后端的库(在我的例子中是 Alfresco)。我非常想创建一个类似于 Flask-SQLAlchemy 和 Django 的“性感”API。问题是我对 Python 的高级编程很陌生。以下是使用该库的想象方式:

# Here is the connector that does the actual request to the CMIS server
c = CMISConnector('url', 'username', 'password')

# Here I declare the model with the desired property fields. A model
# can be either a folder or a document in Alfresco
class SomeModel(c.Model):
    name = c.Property('cmis:name')

# Some query and create examples...
foo = SomeModel.query.first(name='John Doe')
print foo.name
bar = SomeModel(name='Jane Doe')
bar.save()

由于整个对象模型将有一个后端,因此我希望从 Model 继承的每个类都使用相同的连接,而无需显式注册它。

任何帮助将不胜感激:)

I am developing a library that uses CMIS compatible storage as back-end (in my case Alfresco). I would very much like to create a "sexy" API similar to that of Flask-SQLAlchemy and Django. The problem is that I am new to such advanced programming in Python. Here is the imagined way of using this library:

# Here is the connector that does the actual request to the CMIS server
c = CMISConnector('url', 'username', 'password')

# Here I declare the model with the desired property fields. A model
# can be either a folder or a document in Alfresco
class SomeModel(c.Model):
    name = c.Property('cmis:name')

# Some query and create examples...
foo = SomeModel.query.first(name='John Doe')
print foo.name
bar = SomeModel(name='Jane Doe')
bar.save()

Since there will be one back-end for the entire object model I want every class that inherits from Model to use the same connection without having to explicitly register it.

Any help would be much appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2024-11-11 06:12:42

您看过 cmislib 吗?它是用 Python 编写的 CMIS 客户端 API。它允许您使用 Alfresco(或任何其他符合 CMIS 的存储库)中的对象。

API 为您提供“文档”和“文件夹”等对象。我认为你必须编写一些 Django 中间件来完成你想要做的模型工作,但至少 cmislib 可以让你免于编写与 Alfresco 交互的代码。

希望有帮助,

杰夫

Have you taken a look at cmislib? It's a client-side API for CMIS written in Python. It allows you to work with objects in Alfresco (or any other CMIS-compliant repository).

The API gives you objects like "Document" and "Folder". I think you'd have to write some Django middleware to do the model stuff you are trying to do, but at least cmislib will save you from coding the interaction with Alfresco.

Hope that helps,

Jeff

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文