Python 3.9 is now generally available.

google.appengine.ext.db.allocate_id_range

Allocates a range of IDs with specific endpoints.

Once these IDs have been allocated they may be provided manually to newly created entities.

Since the datastore's automatic ID allocator will never assign a key to a new entity that will cause an existing entity to be overwritten, entities written to the given key range will never be overwritten. However, writing entities with manually assigned keys in this range may overwrite existing entities (or new entities written by a separate request) depending on the key range state returned.

This method should only be used if you have an existing numeric id range that you want to reserve, e.g. bulk loading entities that already have IDs. If you don't care about which IDs you receive, use allocate_ids instead.

model Model instance, Key or string to serve as a template specifying the ID sequence in which to allocate IDs. Allocated ids should only be used in entities with the same parent (if any) and kind as this key.
start first id of the range to allocate, inclusive.
end last id of the range to allocate, inclusive.
config datastore_rpc.Configuration to use for this request.

One of (KEY_RANGE_EMPTY, KEY_RANGE_CONTENTION, KEY_RANGE_COLLISION). If not KEY_RANGE_EMPTY, this represents a potential issue with using the allocated key range.