Alexander
Then you need to define the model something like: class Faclin2(db.Entity): facl_descripcion = Optional(str) faccab2s = Required(Faccab2, columns=['facl_facc_id', 'facl_facc_serie']) line_num = Required(int, column=' facl_numlinea') PrimaryKey(faccab2s, line_num)
Alexander
So three column facl_facc_id, facl_facc_serie and facl_numlinea will be composite PK
Anonymous
Thank you very much, I was thinking about that
Anonymous
exactly
Anonymous
Alexander, you are a STAR! Please let me know if I can give you a hand in something (web, translations, documentation, ...)
Anonymous
Now it's working like a charm
Alexander
Super :)
Alexander
It would be helpful to check documentation for some typos and fix the stylistics of sentences, maybe you can do some pull request :) The documentation is at docs.ponyorm.com, and the repository for it is https://github.com/ponyorm/pony-doc
Anonymous
Sure, I'll do it
Alexander
Thanks in advance! :)
Matthew
Are there any downsides to using pony with Python 3 now?
Alexander
I think no
Yurii
Why "Pony"?
Yurii
I think it isn`t serious name for such tool as orm.
Anonymous
And why not? I think is connected with the history
Anonymous
I mean python and Django history
Yurii
If so, then I would like to know this history.
Alexander
I think Teno refers to the Django mascot: http://www.djangopony.com/ https://stackoverflow.com/questions/2115360/what-is-the-deal-with-the-pony-in-python-community In fact, we chose a name for the library before the theme with a Django-pony mascot started, and were very surprised when Django developers began to use pony in its image. We decided to use the name PonyORM for the following reasons: - Ponies are small, smart and strong, just like our library: PonyORM is small (easy to use, easy to install, doesn't depend on other libraries, has intuitive API), smart (make various automatic query optimizations) and powerful (can be used for very advanced applications with complex queries) - Our goal is that working with PonyORM should be as easy and enjoyable as playing with Pony - PonyORM has pretty big amount of "magic" inside, just like some ponies - The name starts with "P" (a popular choose for Python libraries) and "Pony ORM" phrase did not appear in Google search results, so was good from SEO point of view - We don't want to appear too "serious" and "pretentious". Actually, Python language itself was called after a comedy show, so why not to use some silly name for the Python library - Actually, we wanted to initially position Pony as a toy. It is not necessary a bad. Paul Graham wrote: "Don't be discouraged if what you produce initially is something other people dismiss as a toy. In fact, that's a good sign. That's probably why everyone else has been overlooking the idea. The first microcomputers were dismissed as toys. And the first planes, and the first cars. At this point, when someone comes to us with something that users like but that we could envision forum trolls dismissing as a toy, it makes us especially likely to invest."
Anonymous
I agree 100%
Alexander
We do not want our library to be perceived by users as something difficult to use. Our goal is that the learning curve be as flat as possible. The user can easily start to make simple examples and use Pony for simple tasks, and then gradually realize that for complex tasks the Pony is as good as for simple tasks. That is, the library is simple in appearance, but has a great depth and potential. It's somewhat similar to ponies :)
Lucky
Why "Pony"?
Because Friendship is Magic.
Lucky
Actually I have no clue.
Yurii
Thanks, that is interesting. But why actually I am here. I`m writing a smal(or even middle) site using Flask. And I need an ORM. After a long hours of reading advantages and disatvantages of each orm I desided, that Python have two major ORM - SQLAlchemy and PonyORM. For me, SQLAlchemy isn`t very convenient compared to PonyORM. But SQLAlchemy have big comunity and is very popular. What do you think about it? What are the advantages or disadvantages of each of this ORM?
Alexander
1) Query syntax: When you write a query with SQLAlchemy you basically write in some Python-based "dialect" of SQL. The Python->SQL translation process is relatively straightforward. You need to imagine correct SQL query first, and then write it using SQLALchemy syntax. But sometimes you can wonder, "if I need to know final SQL query anyway, why I need write some contrived Python version of it instead of writing SQL directly?" The benefit of using SQLAlchemy query engine is, you can use the same query with different databases, if that is important to you. More important benefit is, if you add some new column to a table, you don't need to manually add it to SELECT part of all queries. With Pony you describe the meaning of a query using generator syntax, and Pony translates it to most efficient SQL (the specific SQL may be different for different databases). There are several benefits of it: - Queries written using Pony feels very "native" and concise. The query language is more high-level than SQL, and very often a query in Pony looks shorter and cleared tnen the resulted correct SQL query. - You can write efficient queries even if you don't remeber the details of SQL syntax, you need to just write a semantically correct Python generator There is also several drawbacks: - Sometimes developer already knows the final SQL query he wants to get, but cannot figure out the correct Pony syntax. In this case he need to search for documentation, do some trial & error attempts, and fially ask me. After he sees the correct Pony syntax, he typically exclaims: "ah, this is so simple!" But, initially it may be not always very intuitive, because the syntax may be very different from SQL. - There are still some SQL queries for which Pony does not have API or cannot translate, like UNION queries or using some database specific functions. In many such cases it is possible to raw SQL queries or raw SQL fragments. Pony has a great support of raw SQL fragments, you can embed into high-level generators to write some specific SQL expression which Pony doesn't know about yet.
Alexander
2) Using existing databases Sometimes you write a new application and create database schema from scratch. In other cases you conect to already existing database. With Pony, it is really easy to define a models (which are called entities in Pony terminology) and create a new database from them. But if you already have a database, it may require more work, because you will need to specify column and table names when defining entities. SQLAlchemy have a more advanced support for existing databases, and can reate models automatically using database reflexion. Pony recently too got a similar tool, but it was not tested for complex situations, like, composite primary keys, etc. The goal of SQLAlchemy is to support any crasy database schema in Python. The goal of Pony is to model information using Entity-Relationship approach, and to create a database schema which is best suited for given ER-diagram.
Alexander
3) Schema evolution After the application is launched it is often required to modify models, for example to add new attributes. The best way to do this is to use some migration tool. SQLAlchemy has such a tool, called Alembic, and Pony doesn't have an official migration tool yet, although you can see preview version here: https://github.com/ponyorm/pony/tree/orm-migrations
Alexander
4) Session management When you are working with database, you need to use transactions in order to avoid data corruption when multiple processes work with the same database at the same time. In order to working with transactions SQLAlchemy and Pony provides the concept of sessions. A session manage transactions and have associated cache of object loaded into memory. Internally the implementation of sessions in Pony and in SQLAlchemy looks similar. But the public API is diferent. In SQLAlchemy you are typicall working with sessions explicitly: you need to create a session and asociate objects with them, while in Pony sessions are managed implicitly, using with db_session context manager and @db_session decorator. The approach of SQLAlchemy is more flexible, but the API is more heavyweight. In typical web application, explicit session management is unnecessary, and I like Pony approach more.
Alexander
5) Supported application types There are different types of applications which are working with database. One type is web application, where the goal is to serve HTTP request as fast as possible: fetch data from the database, generate HTML or JSON response and return it to the user. Pony is designed for that scenario and should be very efficient here. In that scenario, you typically want to retrieve as few data from the database as possible in order to work efficiently. Typically, one HTML page may require at most several thousand objects from the database. Another kind of application is when you retrieve millions of objects in a single session. In that case, it is not always possible to keep all these objects cached into memory, because it may reqire multiple gygabytes of RAM. SQLAlchemy has a way to fetch objects in batches and then expunge them from the cache manually, and Pony currently lacking such features, because that is not a scenary Pony was designed for. Pony has a good syntax support for aggregated queries, but Pony works better if the number of retrieved rows is counted in thousands, not millions.
Alexander
6) New features Sometimes are developer extremely need some feature, and the ORM is not implemented that feature yet. With SQLAlchemy you can try do implement this feature itself, but with Pony you probably need to ask the development team. If the feature is very easy, sometimes we can implement it right away, but more complex features will be placed in queue and may require a long time to be implemented. For example, right now we are working on two big features: hybrid methods and properties (which can be used inside queries and will be translated to SQL) and migration tool, so another requested features will be postponed
Matthew
Make the above into a blog post :)
Alexander
Yes, I probably should :)
Yurii
Wow. It`s pretty good explanation. Thanks a lot. :)
ichux
@akozlovsky You are doing a huge job here. Well done
Alexander
Thanks
ichux
Thanks
Do you know if Web2py DAL?
Alexander
Never used it
Жека
Hi guys
Жека
Is far as I remember pony was proprietary some time ago, wasn't it?
Yurii
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate It`s here.
Alexey
Is far as I remember pony was proprietary some time ago, wasn't it?
Hey Eugene, It wasn’t proprietary, the code was open from the very beginning. Initially we were distributing Pony ORM under dual license - AGPL and a commercial one. Later we changed the license to Apache 2.0. This license allows the user the freedom to use Pony for any purpose, distribute, modify, and to distribute modified versions of it. Free as in beer.
Alexander
Is there already documentation out there? Or example code? Just the branch itself isn't a good entry point :D
The migration subpackage has short readme description, we'll extend it with more information
Juan Antonio
Are you the famous nigerian prince from the emails?
Жека
Lol
ichux
Are you the famous nigerian prince from the emails?
Hell no. I'm a Python Programmer with over 12 year experience
Juan Antonio
:P
Жека
but... your name...
ichux
I'm the chairperson of Python Nigeria Community, registered with the Nigerian body meant for such
ichux
I'm a PSF member with voting rights and I also serve at the Grants committee level
ichux
I'm Chukwudi Nwachukwu
Жека
What is PSF?
ichux
https://ng.linkedin.com/in/ichux
ichux
Python Software Foundation
Жека
Oh
ichux
Are you the famous nigerian prince from the emails?
So, when I said I'll donate, I mean every part of it.
Juan Antonio
It was a simple joke 😆
ichux
I don't involved in any illegal activities. I have my name and image to protect @Mancuerna
ichux
It was a simple joke 😆
Indeed, but it's a stark reality of what obtains in this part of the world
Alexander
Chukwudi, I'm sorry if some replies were unappropriate. I think the guys just wanted to make a joke. We are greatly appreciate your participation in this chat!
ichux
I have loved pony from the day 1. Another one is Whoosh and SQLAlchemy
ichux
I'm active in those places too
ichux
But I just watch and contribute less
Alexey
Talking about donations - actually we’d like to add such a possibility to the site. What options are there besides PayPal donate button? They say PayPal can lock an account at any time without any explanation...
ichux
Talking about donations - actually we’d like to add such a possibility to the site. What options are there besides PayPal donate button? They say PayPal can lock an account at any time without any explanation...
PayPal doesn't work well for us here. But I can send, only that I can't receive. Talk of one challenge we face here cos of the *famous Nigerian princes*
Жека
you know, it is something like "russians with bear and vodka" or "ukrainians with lard and revolutions"
Alexander
Oops, I forgot to feed my bear today, and there is nothing except vodka in my fridge
ichux
But are there other options to receive donations, other than PayPal?
Right now, unless I ask around, I can't really answer yes. I'm speaking as a Nigerian living here. But of course, there are other ways for other countries
Alexander
Don't fear, it a small one
Alexander
Actually, SQLAlchemy and other libraries like MobX use PayPal for donations. But there are many horros stories over the internet that PayPal can appropriate money from the account at any time, justifying it that the donations via PayPal are possible for specially registered non-profit organizations only, not for personal accounts and commercial organizations.
Henri
Hmm never heard that. Using PayPal for donations and it's ok. Beside that the fee especially for small donations is quite big.
Henri
BTW I also have a bear running here around and he's quite big... and wild
ichux
Don't fear, it a small one
Waoh! I only see it on Satellite channels