Skip to content

Instantly share code, notes, and snippets.


Tom Christie tomchristie

View GitHub Profile
import requests3
import trio
session = requests3.AsyncSession()
async def main():
async def request():
r = await session.get('', stream=False)
from inspect import iscoroutinefunction, isawaitable
import sys
from collections import deque
# NOTE: this follows the contextlib.ExitStack implementation
class _BaseExitStack:
def __init__(self):
roadsideseb /
Last active Apr 4, 2018
Job sites for Django and Python developers
g-cassie /
Created Aug 20, 2015
This is how we are handling complex permissions right now (this is actually a grossly simplified version). The main problem is permissions logic is split between multiple places. It would be nice to consolidate all permissions logic in Additionally it would be nice to make this more composable so you can have AdminPermission and …
class Organization(models.Model):
name = models.CharField()
class Project(models.Model):
name = models.CharField()
users = models.ManyToManyField('User', related_name='users', through='UserProjectPermission')
organization = models.ForeignKey(Organization)
marteinn /
Last active Sep 29, 2021
Using the Fetch Api with Django Rest Framework

Using the Fetch Api with Django Rest Framework


First, make sure you use the SessionAuthentication in Django. Put this in your

# Django rest framework
gdamjan /
Last active Nov 10, 2019
Python 3.5 async/await with aiohttp, parallel or sequential
import aiohttp
import asyncio
async def get_body(url):
response = await aiohttp.request('GET', url)
raw_html = await
return raw_html
async def main():
# run them sequentially (but the loop can do other stuff in the meanwhile)
View gist:598fa75e22bdfa44cf47

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

from rest_framework import serializers
class HyperlinkedIdentityField(serializers.HyperlinkedIdentityField):
This is a performance wrapper for HyperlinkedIdentityField.
We save a ton of time by not calling reverse potentially
thousands of times per request.
def __init__(self, *args, **kwargs):

Where people struggle learning Django

Over the last 3 years or so I've helped a bunch of companies, small and large, switch to Django. As part of that, I've done a lot of teaching Django (and Python) to people new to the platform (and language). I'd estimate I've trained something around 200-250 people so far. These aren't people new to programming — indeed, almost all of them are were currently employed as software developers — but they were new to Python, or to Django, or to web development, or all three.

In doing so, I've observed some patterns about what works and what doesn't. Many (most) of the failings have been my own pedagogical failings, but as I've honed my coursework and my skill I'm seeing, time and again, certain ways that Django makes itself difficult to certain groups of users.

This document is my attempt at organizing some notes around what ways different groups struggle. It's not particularly actionable — I'm not making any arguments about what Django should or shouldn't do (at least

mjumbewu /
Last active Nov 28, 2019
A Django REST Framework renderer which renders data from DRF serializers into CSV. The underlying functions will render any hierarchy of Python primitive containers to CSV.
import csv
from collections import defaultdict
from rest_framework.renderers import *
from StringIO import StringIO
class CSVRenderer(BaseRenderer):
Renderer which serializes to CSV