Gramex 1.87 supports FormHandler argument typing, distributed user stores, flexible deletions, and more.
FormHandler filter values are converted from strings to the column type, where possible.
To explicitly set the type, use argstype
:
url:
flags:
pattern: /people
handler: FormHandler
kwargs:
url: people.csv
argstype:
age: { type: int }
weight: { type: float }
is_married: { type: bool }
date_of_birth: { type: pd.to_datetime }
date_of_death: { type: pd.to_datetime(_val) if _val else None }
argstype
is a dictionary of column names and their types. The type can be:
int
, float
, bool
, datetime.date
, datetime.datetime
_val
and returns a value, e.g. pd.to_datetime(_val)
Note: argstype
values can also include an {expanding: true}
to treat values as lists.
This is used in FormHandler queries to
prevent SQL injection in the IN
operator.
User information (including attributes) is stored in a user store that is configured as follows:
storelocations:
user:
url: sqlite:///$GRAMEXDATA/auth.user.db
table: user
columns:
key: { type: TEXT, primary_key: true }
value: { type: TEXT }
If you use Gramex on multiple servers, change this to a remote database with the same syntax as
FormHandler. For example, add this in your gramex.yaml
:
storelocations:
user:
url: postgresql://$USER:$PASS@server/db
# url: mysql+pymysql://$USER:$PASS@server/db
# ...
table: user
FormHandler DELETE required a primary key to be specified via kwargs.id
.
This is no longer required. DELETE now works exactly like GET, except that it deletes rows instead of filtering them.
Similarly, gramex.data.delete()
now works like gramex.data.filter()
. For example:
# Fetches data based on a filter
rows = gramex.data.filter('sqlite:///sales.db', table='sales', where={'city': 'Olso'})
# Returns the number of rows deleted. Same as len(rows)
count = gramex.data.delete('sqlite:///sales.db', table='sales', where={'city': 'Olso'})
If we use OFFSET or LIMIT with MS SQL, we must specify an ORDER BY clause. Otherwise, it raises:
MSSQL requires an order_by when using an OFFSET or a non-simple LIMIT
.
Gramex now does this automatically. If the query is not sorted, Gramex sorts by the first column in the table. #626
The first version of the Admin app (imported from $GRAMEXAPPS/admin/gramex.yaml
) was deprecated in Gramex 1.33.
This version of Gramex removes it.
GET
method to all FunctionHandlers, even if it only mentions a POST method. Fixed #660gramex.yaml
specifies the listen.port as a string (e.g. port: '9988'
), Gramex logging would fail. Fixed #664.conda
folder which is protected by FileHandler by default. FileHandler now specifically allows .conda
folders. Fixed #670Gramex 1.87 is backward compatible with previous releases unless the release notes say otherwise. Automated builds test this.
Every Gramex release is tested for security vulnerabilities using the following tools.
The Gramex code base has: