Skip to main content

Official Python client for the Jules API

Project description

Jules API Python Client

PyPI version License: MIT Python Versions Apology: We apologize for mistakenly presenting this library as official in earlier versions. This is an unofficial library.

Unofficial Python client library for the Jules API.

Installation

pip install jules-api

Usage

from jules_api import JulesClient
from jules_api import CreateSessionRequest, SourceContext, GithubRepoContext, SendMessageRequest

# Initialize the client with your API key
client = JulesClient(api_key="YOUR_API_KEY_HERE")

# List available sources
sources_response = client.list_sources()
print("Available sources:")
for source in sources_response.sources:
    print(f"- {source.id}: {source.name}")
    if source.github_repo:
        print(f"  GitHub: {source.github_repo.owner}/{source.github_repo.repo}")

if not sources_response.sources:
    print("No sources found. Please connect a GitHub repository in the Jules web app first.")
    exit(1)

# Create a new session
first_source = sources_response.sources[0]
session_request = CreateSessionRequest(
    prompt="Create a simple web app that displays 'Hello from Jules!'",
    source_context=SourceContext(
        source=first_source.name,
        github_repo_context=GithubRepoContext(starting_branch="main")
    ),
    title="Hello World App Session"
)

session = client.create_session(session_request)
print(f"Created session: {session.id}")
print(f"Title: {session.title}")
print(f"Prompt: {session.prompt}")

# Send a message to the agent
message_request = SendMessageRequest(
    prompt="Please add some styling to make it look more attractive."
)
client.send_message(session.id, message_request)
print("Message sent to the agent!")

# List activities (optional)
activities_response = client.list_activities(session.id, page_size=10)
print(f"\nFound {len(activities_response.activities)} activities:")
for activity in activities_response.activities:
    content = activity.content or "No content"
    if len(content) > 100:
        content = content[:100] + "..."
    print(f"- {activity.type}: {content}")

Alternative Client Creation

You can also use the convenience function:

from jules_api import create_client

client = create_client("YOUR_API_KEY_HERE")

API Reference

JulesClient

Constructor

client = JulesClient(api_key="your_api_key", base_url="https://jules.googleapis.com/v1alpha")

Parameters:

Methods

list_sources(next_page_token=None)

List all available sources connected to your Jules account.

Parameters:

  • next_page_token: Token for pagination (optional)

Returns: ListSourcesResponse object with sources array and optional next_page_token

create_session(request)

Create a new session.

Parameters:

  • request: CreateSessionRequest object with session parameters

Returns: Session object representing the created session

list_sessions(page_size=None, next_page_token=None)

List your sessions.

Parameters:

  • page_size: Maximum number of sessions to return (optional)
  • next_page_token: Token for pagination (optional)

Returns: ListSessionsResponse object with sessions array and optional next_page_token

approve_plan(session_id)

Approve the latest plan for a session (use when require_plan_approval is True).

Parameters:

  • session_id: The session ID string (required)
list_activities(session_id, page_size=None, next_page_token=None)

List activities for a session.

Parameters:

  • session_id: The session ID string (required)
  • page_size: Maximum number of activities to return (optional)
  • next_page_token: Token for pagination (optional)

Returns: ListActivitiesResponse object with activities array and optional next_page_token

send_message(session_id, request)

Send a message to the agent in a session.

Parameters:

  • session_id: The session ID string (required)
  • request: SendMessageRequest object with the message
get_session(session_id)

Get details of a specific session.

Parameters:

  • session_id: The session ID string (required)

Returns: Session object

get_source(source_id)

Get details of a specific source.

Parameters:

  • source_id: The source ID string (required)

Returns: Source object

Models

Request/Response Models

  • CreateSessionRequest: Used to create new sessions
  • SendMessageRequest: Used to send messages to agents
  • ListSourcesResponse: Response from listing sources
  • ListSessionsResponse: Response from listing sessions
  • ListActivitiesResponse: Response from listing activities
  • Session: Session information
  • Source: Source information
  • Activity: Activity information

Data Models

  • SourceContext: Context for session sources
  • GithubRepoContext: Additional context for GitHub repositories
  • GithubRepo: GitHub repository information

All models use Pydantic for validation and type hints.

Authentication

All API requests require authentication using your Jules API key. Get your API key from the Settings page in the Jules web app. The client automatically includes the key in the X-Goog-Api-Key header for all requests.

Important: Keep your API keys secure. Never commit them to version control or expose them in client-side code.

Set your API key as an environment variable:

export JULES_API_KEY=your_api_key_here

Error Handling

The client raises requests.HTTPError exceptions for HTTP errors. Always wrap API calls in try-except blocks:

from requests.exceptions import HTTPError

try:
    session = client.create_session(request)
    print("Success:", session)
except HTTPError as e:
    print(f"HTTP Error: {e}")
    print(f"Status Code: {e.response.status_code}")
    print(f"Response: {e.response.text}")

Type Hints

This library uses modern Python type hints throughout. Your IDE should provide excellent autocomplete and type checking support.

Contributing

Contributions are welcome! Please read our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jules-api-1.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jules_api-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file jules-api-1.0.1.tar.gz.

File metadata

  • Download URL: jules-api-1.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for jules-api-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d07e0cf55ff32eefae962e51e755167013c3c997046560ab1ac30f5cf48296e2
MD5 6bb1d310399e5253ea085017ba11a3f4
BLAKE2b-256 0aca15a32c6a1c70b20333b419c665f2ac841381f452ea34a8aa2100547635ac

See more details on using hashes here.

File details

Details for the file jules_api-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: jules_api-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for jules_api-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d141073e7150133c450b4d86596e7335a3ab215808fe3948756e4f5ae90cd974
MD5 f5a77c4dbb4bbe4ee23d946fecd14b8f
BLAKE2b-256 f801092b2f4d5b711c06dca8aea53c35d22d84170a29f3697572c61e07e2d062

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page