python-upwork

repository·master·Indexed 41 days ago

https://github.com/upwork/python-upwork

A Python client library for interacting with the Upwork API using OAuth1 authentication. It simplifies the OAuth1 handshake and provides high-level methods for standard HTTP verbs (GET, POST, PUT, DELETE) to access resources including My Info, Custom Payments, Hiring, and Job and Freelancer Profiles. Requires Python 3.8 or higher.

Tokens
1.2K
Snippets
5
Records
7
Agent score
2%

What's inside Upwork Python SDK

  1. Configure and run a python-upwork application

    master

    To use the library, you must obtain a consumer_key and consumer_secret from the Upwork API Center. You can then use these credentials in your application script (e.g., myapp.py) to authenticate via OAuth 1.0a.

    # Example conceptual usage in myapp.py
    consumer_key = 'YOUR_CONSUMER_KEY'
    consumer_secret = 'YOUR_CONSUMER_SECRET'
    
    # Follow library instructions to initialize client with these credentials
  2. Perform OAuth1 Authorization Flow

    master

    To authorize a user, follow these steps using the Client methods:

    1. Get Request Token: Call get_request_token() to obtain a temporary request token and secret.
    2. Get Authorization URL: Call get_authorization_url(callback_url=None) to generate the URL where the user must be redirected to grant access. If you provide a callback_url, it will be included in the parameters.
    3. Get Access Token: After the user authorizes the application and provides a verifier (obtained from the callback), call get_access_token(verifier) to exchange the request token for a permanent access token and access token secret. These are automatically stored in your config object.
    # 1. Get request token
    request_token, request_token_secret = client.get_request_token()
    
    # 2. Get the URL for the user to visit
    auth_url = client.get_authorization_url(callback_url='https://your-app.com/callback')
    print(f"Please visit: {auth_url}")
    
    # 3. After user visits and redirects back with a verifier...
    access_token, access_token_secret = client.get_access_token(verifier='USER_VERIFIER')
  3. Supported Upwork API resources

    master

    The python-upwork library provides bindings for the following Upwork API resources:

    • My Info
    • Custom Payments
    • Hiring
    • Job and Freelancer Profile
    • Search Jobs and Freelancers
    • Organization
    • Messages
    • Time and Financial Reporting
    • Metadata
    • Snapshot
    • Team
    • Workd Diary
    • Activities
  4. Execute HTTP requests with Client

    master

    Once authorized, use the following methods to interact with Upwork API endpoints. All methods return the parsed JSON response.

    • get(uri, params=None): Executes a GET request.
    • post(uri, params=None): Executes a POST request. For POST, params is sent as a JSON body.
    • put(uri, params=None): Executes a PUT request. For PUT, params is sent as a JSON body.
    • delete(uri, params=None): Executes a DELETE request. Note that for DELETE, the http_method parameter is automatically added to the request body.
    # Example GET request
    user_data = client.get('/users/me')
    
    # Example POST request with JSON body
    new_job = client.post('/jobs', params={'title': 'Python Developer', 'description': '...'})
    
    # Example PUT request
    client.put('/jobs/12345', params={'status': 'closed'})
    
    # Example DELETE request
    client.delete('/jobs/12345')
  5. Initialize the Client class

    master

    The Client class is the primary entrypoint for interacting with the Upwork API using OAuth1 authorization. To initialize it, you must provide an instance of the upwork.Config class, which contains your configuration keys and tokens (such as consumer_key, consumer_secret, and verify_ssl).

    from upwork import Config, Client
    
    config = Config(
        consumer_key='YOUR_CONSUMER_KEY',
        consumer_secret='YOUR_CONSUMER_SECRET',
        verify_ssl=True
    )
    client = Client(config)